Advertisement
mengyuxin

form_filler.py

Jan 14th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.82 KB | None | 0 0
  1. #!/usr/bin/python
  2. # form_filler.py - Automatically fills in the form.
  3.  
  4. import pyautogui, time
  5.  
  6. # Set these to the correct coordinates for your particular computer.
  7. nameField = (648, 319)
  8. submitButton = (651, 817)
  9. submitButtonColor = (75, 141, 249)
  10. submitAnotherLink = (760, 224)
  11.  
  12. formData = [{'name': 'Alice',
  13.          'fear': 'eavesdroppers',
  14.          'source': 'wand',
  15.          'robocop': 4,
  16.          'comments': 'Tell Bob I said hi.'},
  17.             {'name': 'Bob',
  18.          'fear': 'bees',
  19.          'source': 'amulet',
  20.          'robocop': 4,
  21.          'comments': 'n/a'},
  22.             {'name': 'Carol',
  23.          'fear': 'puppets',
  24.          'source': 'crystal ball',
  25.          'robocop': 1,
  26.          'comments': 'Please take the puppets out of the break room.'},
  27.             {'name': 'Alex Murphy',
  28.          'fear': 'ED-209', 'source':
  29.          'money', 'robocop': 5,
  30.          'comments': 'Protect the innocent. Serve the public trust. Uphold the law.'},
  31.             ]
  32.  
  33. pyautogui.PAUSE = 0.5
  34.  
  35. for person in formData:
  36.     # Give the user a chance to kill the script.
  37.     print('>>> 5 SECOND PAUSE TO LET USER PRESS CTRL-C <<<')
  38.     time.sleep(5)
  39.  
  40.     # Wait until the form page has loaded.
  41.     while not pyautogui.pixelMatchesColor(submitButton[0], submitButton[1], submitButtonColor):
  42.         time.sleep(0.5)
  43.  
  44.     print('Entering %s info...' % (person['name']))
  45.     pyautogui.click(nameField[0], nameField[1])
  46.  
  47.     # Fill out the Name field.
  48.     pyautogui.typewrite(person['name'] + '\t')
  49.  
  50.     # Fill out the Greatest Fear(s) field.
  51.     pyautogui.typewrite(person['fear'] + '\t')
  52.  
  53.     # Fill out the Source of Wizard Powers field.
  54.     if person['source'] == 'wand':
  55.         pyautogui.typewrite(['down', '\t'])
  56.     elif person['source'] == 'amulet':
  57.         pyautogui.typewrite(['down', 'down', '\t'])
  58.     elif person['source'] == 'crystal ball':
  59.         pyautogui.typewrite(['down', 'down', 'down', '\t'])
  60.     elif person['source'] == 'money':
  61.         pyautogui.typewrite(['down', 'down', 'down', 'down', '\t'])
  62.  
  63.     # Fill out the Robocop field.
  64.     if person['robocop'] == 1:
  65.         pyautogui.typewrite([' ', '\t'])
  66.     elif person['robocop'] == 2:
  67.         pyautogui.typewrite(['right', '\t'])
  68.     elif person['robocop'] == 3:
  69.         pyautogui.typewrite(['right', 'right', '\t'])
  70.     elif person['robocop'] == 4:
  71.         pyautogui.typewrite(['right', 'right', 'right', '\t'])
  72.     elif person['robocop'] == 5:
  73.         pyautogui.typewrite(['right', 'right', 'right', 'right', '\t'])
  74.  
  75.     # Fill out the Additional comments field.
  76.     pyautogui.typewrite(person['comments'] + '\t')
  77.  
  78.     # Click Submit.
  79.     pyautogui.press('enter')
  80.  
  81.     # Wait until form page has loaded.
  82.     print('Clicked Submit.')
  83.     time.sleep(5)
  84.  
  85.     # Click the Submit another response link.
  86.     pyautogui.click(submitAnotherLink[0], submitAnotherLink[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement