Skip to content

Commit cd688af

Browse files
committed
DOC: Updating examples and making sure that they work properly.
1 parent 44ce5eb commit cd688af

File tree

7 files changed

+131
-111
lines changed

7 files changed

+131
-111
lines changed

examples/contact/botcity_contact.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
This is an example using the botcity framework as a script.
3+
"""
14
from botcity.core import *
25

36
# Add the resource images

examples/rpa-challenge/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
# RPA Challenge
22

3-
The examples in this folder are were created to solve the challenges available at the RPA Challenge Website (http://www.rpachallenge.com/).
3+
The examples in this folder are were created to solve the challenges
4+
available at the RPA Challenge Website (http://www.rpachallenge.com/).
45

6+
Make sure to install the needed requirements with:
7+
8+
```python
9+
pip install -r requirements.txt
10+
```
11+
12+
## Examples
13+
14+
- **input_bot.py**: This example demonstrates how to use computer vision in two ways (serial and parallel) to
15+
locate the fields on the screen and fill in the values.
16+
17+
- **input_bot-content.py**: This example leverages the page content and navigate the fields using the keyboard.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import botcity.core.config as cfg
2+
3+
import os
4+
import sys
5+
import pandas
6+
import requests
7+
from botcity.core import DesktopBot
8+
9+
# Speed up without sleep after action.
10+
cfg.DEFAULT_SLEEP_AFTER_ACTION = 20
11+
12+
13+
class Bot(DesktopBot):
14+
def action(self, execution):
15+
# Add the resource images
16+
self.add_image("start", self.get_resource_abspath("start.png"))
17+
18+
# Download Input Spreadsheet
19+
r = requests.get("http://www.rpachallenge.com/assets/downloadFiles/challenge.xlsx")
20+
21+
if r.status_code != 200:
22+
sys.exit('Error fetching the challenge spreadsheet.')
23+
24+
# Use Pandas to load the Excel Spreadsheet as a DataFrame:
25+
df = pandas.read_excel(r.content)
26+
df.dropna(axis='columns', inplace=True)
27+
28+
df.columns = df.columns.str.strip()
29+
30+
# Navigate to the website
31+
self.browse("http://www.rpachallenge.com/")
32+
33+
# Find and click into the Start button
34+
self.find("start")
35+
self.click()
36+
37+
for index, row in df.iterrows():
38+
# Click into main area of the page
39+
self.control_a()
40+
self.control_c()
41+
content = self.get_clipboard()
42+
43+
self.click_at(1000, 200)
44+
field_order = [x for x in content[content.rfind('!') + 1:].split(os.linesep) if x in df.columns]
45+
46+
for f in field_order:
47+
self.tab()
48+
value = row[f]
49+
self.copy_to_clipboard(str(value))
50+
self.control_v()
51+
52+
self.enter()
53+
54+
55+
if __name__ == '__main__':
56+
Bot.main()

examples/rpa-challenge/input-forms/input_bot-fast.py

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,71 @@
11
import sys
22
import pandas
33
import requests
4-
import botcity.core.config as cfg
4+
from botcity.core import DesktopBot
55

6-
# Speed up without sleep after action.
7-
cfg.DEFAULT_SLEEP_AFTER_ACTION = 0
86

9-
# Add the resource images
10-
add_image("First Name", "./resources/first_name.png")
11-
add_image("Last Name", "./resources/last_name.png")
12-
add_image("Company Name", "./resources/company_name.png")
13-
add_image("Role in Company", "./resources/role.png")
14-
add_image("Address", "./resources/address.png")
15-
add_image("Email", "./resources/email.png")
16-
add_image("Phone Number", "./resources/phone.png")
17-
add_image("start", "./resources/start.png")
18-
add_image("submit", "resources/submit_large.png")
7+
class Bot(DesktopBot):
8+
def action(self, execution=None):
9+
# Add the resource images
10+
self.add_image("First Name", self.get_resource_abspath("first_name.png"))
11+
self.add_image("Last Name", self.get_resource_abspath("last_name.png"))
12+
self.add_image("Company Name", self.get_resource_abspath("company_name.png"))
13+
self.add_image("Role in Company", self.get_resource_abspath("role.png"))
14+
self.add_image("Address", self.get_resource_abspath("address.png"))
15+
self.add_image("Email", self.get_resource_abspath("email.png"))
16+
self.add_image("Phone Number", self.get_resource_abspath("phone.png"))
17+
self.add_image("start", self.get_resource_abspath("start.png"))
18+
self.add_image("submit", self.get_resource_abspath("submit.png"))
1919

20-
# Download Input Spreadsheet
21-
r = requests.get("http://www.rpachallenge.com/assets/downloadFiles/challenge.xlsx")
20+
# Download Input Spreadsheet
21+
r = requests.get("http://www.rpachallenge.com/assets/downloadFiles/challenge.xlsx")
2222

23-
if r.status_code != 200:
24-
sys.exit('Error fetching the challenge spreadsheet.')
23+
if r.status_code != 200:
24+
sys.exit('Error fetching the challenge spreadsheet.')
2525

26-
# Use Pandas to load the Excel Spreadsheet as a DataFrame:
27-
df = pandas.read_excel(r.content)
28-
df.dropna(axis='columns', inplace=True)
26+
# Use Pandas to load the Excel Spreadsheet as a DataFrame:
27+
df = pandas.read_excel(r.content)
28+
df.dropna(axis='columns', inplace=True)
2929

30-
# Create a list with the column names
31-
labels = [c.strip() for c in df.columns]
32-
labels.append("submit")
30+
# Create a list with the column names
31+
labels = [c.strip() for c in df.columns]
32+
labels.append("submit")
3333

34-
# Navigate to the website
35-
browse("http://www.rpachallenge.com/")
34+
# Navigate to the website
35+
self.browse("http://www.rpachallenge.com/")
3636

37-
# Find and click into the Start button
38-
find("start")
39-
click()
37+
# Find and click into the Start button
38+
self.find("start", waiting_time=50000)
39+
self.click()
4040

41-
USE_FIND_MULTIPLE = True
41+
USE_FIND_MULTIPLE = True
4242

43-
if USE_FIND_MULTIPLE:
44-
### Using Find Multiple
45-
for index, row in df.iterrows():
46-
results = find_multiple(labels, matching=0.8)
47-
for idx, (label, ele) in enumerate(results.items()):
48-
if ele is None:
49-
sys.exit(f'Could not find element for field: {label}')
50-
x, y = ele.left, ele.top
51-
if label == 'submit':
52-
click_at(x + 10, y + 10)
53-
else:
54-
click_at(x + 10, y + 30)
55-
copy_to_clipboard(str(row[df.columns[idx]]))
56-
paste()
57-
else:
58-
## Using Find one-by-one
59-
for index, row in df.iterrows():
60-
for col in df.columns:
61-
entry_value = row[col]
62-
find_text(col.strip(), matching=0.8)
63-
click_relative(10, 30)
64-
kb_type(str(entry_value))
65-
find("submit")
66-
click()
67-
wait(500)
43+
if USE_FIND_MULTIPLE:
44+
# Using Find Parallel
45+
for index, row in df.iterrows():
46+
results = self.find_multiple(labels, matching=0.8)
47+
for idx, (label, ele) in enumerate(results.items()):
48+
if ele is None:
49+
sys.exit(f'Could not find element for field: {label}')
50+
x, y = ele.left, ele.top
51+
if label == 'submit':
52+
self.click_at(x + 10, y + 10)
53+
else:
54+
self.click_at(x + 10, y + 30)
55+
self.copy_to_clipboard(str(row[df.columns[idx]]))
56+
self.paste()
57+
else:
58+
# Using Find Serial Mode
59+
for index, row in df.iterrows():
60+
for col in df.columns:
61+
entry_value = row[col]
62+
self.find_text(col.strip(), matching=0.8)
63+
self.click_relative(10, 30)
64+
self.kb_type(str(entry_value))
65+
self.find("submit")
66+
self.click()
67+
self.wait(500)
68+
69+
70+
if __name__ == '__main__':
71+
Bot.main()
636 Bytes
Loading
-4.55 KB
Binary file not shown.

0 commit comments

Comments
 (0)