Skip to content

Instantly share code, notes, and snippets.

@JustAnAverageGuy
Last active June 28, 2025 19:24
Show Gist options
  • Save JustAnAverageGuy/d82df49860c342de3dfc1f13ff4d066d to your computer and use it in GitHub Desktop.
Save JustAnAverageGuy/d82df49860c342de3dfc1f13ff4d066d to your computer and use it in GitHub Desktop.
fills OE preference form
#!/usr/bin/env python3
import sys
import pyautogui as pg
# List of form courses generated as
# JSON.stringify([...$0.children].map(x => x.innerHTML).filter(k => k))
FORM_COURSES = [ # {{{
'BM-201',
'EC-423',
'CHI-403',
'CHE-321',
'CE-353',
'EP-361',
'MT-312',
'MA-311',
'ME-433',
'BC-311',
'MN-412',
'LLG-309',
'AR-316',
'CSE-342',
'PH-323',
'EO-201',
'MS-311',
'BM-302',
'MCR-304',
'EC-449',
'CHI-421',
'CHE-331',
'CE-422',
'EP-511',
'MT-322',
'MA-312',
'ME-454',
'BC-312',
'MN-461',
'HSL-301',
'AR-318',
'CSE-574',
'PH-331',
'EE-319',
'MS-304',
'PYM-545',
'HPH-305',
'AI-111',
'AI-112',
'CHE-573',
]
# }}}
PREFERENCE_ORDER = [ # {{{
'EC-449',
'EO-201',
'MA-311',
'MA-312',
'HPH-305',
'HSL-301',
'LLG-309',
'CSE-574',
'AI-111',
'CSE-342',
'AI-112',
'BM-201',
'EC-423',
'CHI-403',
'CHE-321',
'CE-353',
'EP-361',
'MT-312',
'ME-433',
'BC-311',
'MN-412',
'AR-316',
'PH-323',
'MS-311',
'BM-302',
'MCR-304',
'CHI-421',
'CHE-331',
'CE-422',
'EP-511',
'MT-322',
'ME-454',
'BC-312',
'MN-461',
'AR-318',
'PH-331',
'EE-319',
'MS-304',
'PYM-545',
'CHE-573',
]
# }}}
def main():
assert 40 == len(PREFERENCE_ORDER) == len(set(PREFERENCE_ORDER))
assert set(PREFERENCE_ORDER) == set(FORM_COURSES)
indices = {j: i for i, j in enumerate(FORM_COURSES)}
try:
point = pg.locateOnScreen('./root-marker.png', grayscale=True)
assert point is not None
except pg.ImageNotFoundException:
print('SECTION NOT FOUND')
return 1
left, top, *_ = point
pg.moveTo(left, top)
pg.click()
pg.press('tab', 2) # make the selection go to the first radio button in the section
for course in PREFERENCE_ORDER:
position = indices[course]
if position > 0:
pg.press('right', position) # move to the correct column
# if the position is zero, then you are already at the first column and is correct
pg.press('space') # select the radiobutton (won't error even if already selected)
pg.press('tab') # go to the next row (or next section if the last row, which in this case is the submit button)
if __name__ == '__main__':
sys.exit(main())
# vim: fdm=marker
@JustAnAverageGuy
Copy link
Author

root-marker.png file, used to find the bullet section

root-marker

@JustAnAverageGuy
Copy link
Author

demo usage video

form-filler-demo-email-blurred.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment