Skip to content

Commit 0be4531

Browse files
End of Coursesudo git add .
1 parent f7a1d8f commit 0be4531

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/python3.5
2+
3+
4+
"""
5+
6+
Author: Samrat Banerjee
7+
Dated: 10/09/2018
8+
Description: Project: Displays the mouse cursor's current position.
9+
10+
"""
11+
12+
import pyautogui
13+
print('Press Ctrl-C to quit.')
14+
15+
try:
16+
while True:
17+
# Get and print the mouse coordinates.
18+
x, y = pyautogui.position()
19+
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
20+
print(positionStr, end='')
21+
print('\b' * len(positionStr), end='', flush=True)
22+
23+
24+
except KeyboardInterrupt:
25+
print('\nDone.')

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
* [x] Chapter 14 – Working with CSV Files and JSON Data
3636
* [x] Chapter 15 – Keeping Time, Scheduling Tasks, and Launching Programs
3737
* [x] Chapter 16 – Sending Email and Text Messages
38-
* [ ] Chapter 17 – Manipulating Images
39-
* [ ] Chapter 18 – Controlling the Keyboard and Mouse with GUI Automation
38+
* [x] Chapter 17 – Manipulating Images
39+
* [x] Chapter 18 – Controlling the Keyboard and Mouse with GUI Automation

0 commit comments

Comments
 (0)