11import sys
22import pandas
33import 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 ()
0 commit comments