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