2 minutes
Web automation with Selenium
If you are a fellow student of The Open University, you have realized that sometimes the emails notifying of the results of your module are sent up to two days after the result have actually being published.
That situation leave you with checking manually the website of the Open University for your result, but there is a better way.
Selenium is a web automation suite that can be used in any language. It simulates the behavior of an user, and you can retrieve the information you are interested upon.
In our case, we want to log-in in the Open University, go to the section of the results of our module and check if the result have been published.
I have made a small python program to do precisely that:
#!/usr/bin/env python
from selenium import webdriver
import geckodriver_autoinstaller
import smtplib
geckodriver_autoinstaller.install()
opts = webdriver.FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(options=opts)
# Change the following line with your module and edition (ex. B839_2019K)
webpage='https://msds.open.ac.uk/students/module.aspx?c=B839_2019K&cr=1#result'
username = 'TYPE YOUR USERNAME Fxxxxxx'
password = 'TYPE YOUR PASSWORD'
username_xpath='//*[@id="username"]'
password_xpath='//*[@id="password"]'
login_button_xpath='//*[@id="Form1"]/div[1]/input'
module_result='//*[@id="ou-content"]/div/div[1]'
browser.get(webpage)
browser.find_element_by_xpath(username_xpath).send_keys(username)
browser.find_element_by_xpath(password_xpath).send_keys(password)
browser.find_element_by_xpath(login_button_xpath).click()
result_text = browser.find_element_by_xpath(module_result).text
# Change the following line with the text you see right now (while you are waiting for your results)
if 'We plan to make your module result available on Tuesday 8 December 2020' not in result_text:
server = smtplib.SMTP('localhost')
message = 'Subject: Results MBA \n\n{}'.format(result_text)
server.sendmail('your@email.address', 'your@email.address', message)
Remember to change the code and adapt it to your case. You will also need to have a local email server configure properly to send emails directly or using a relay (I am using my gmail account as a relay for my local postfix server).
Last, you can trigger the script once or twice per day with cron
and be notified about the results of your modules.
Good luck, and I hope this trick will relieve your waiting stress.