Skip to content

Instantly share code, notes, and snippets.

@lukicdarkoo
Created August 22, 2019 12:14
Show Gist options
  • Save lukicdarkoo/6414e3803d62f6564362ab2044561b1b to your computer and use it in GitHub Desktop.
Save lukicdarkoo/6414e3803d62f6564362ab2044561b1b to your computer and use it in GitHub Desktop.
EPFL: Notify when a course state is changed on IS-Academia
import sys
import time
import smtplib
import logging
from pyquery import PyQuery
from requests_html import HTMLSession
logging.basicConfig(filename='isa.log', format='[%(asctime)s] %(message)s', filemode='w', level=logging.INFO)
logger = logging.getLogger('isa')
UPDATE_PERIOD = 10
LOGIN_URL = 'https://isa.epfl.ch/imoniteur_ISAP/!logins.tryToConnect'
ISA_USER = '[email protected]'
ISA_PASS = 'secret_isa_password'
XML_URL = 'https://isa.epfl.ch/imoniteur_ISAP/!PORTAL14S.portalCell?ww_k_cell=1809191822'
COURSE_ID = '123456789'
EMAIL_PASSWORD = 'secret_gmail_password'
EMAIL_PORT = 587
EMAIL_ADDRESS = '[email protected]'
EMAIL_RECEIVER = '[email protected]'
EMAIL_MESSAGE = """\
Subject: The course state is changed
Hurry, https://isa.epfl.ch/imoniteur_ISAP/PORTAL14S.htm#tab26"""
def notify(length=5, period=0.2):
for _ in range(length):
sys.stdout.write('\a')
sys.stdout.flush()
time.sleep(period)
def main():
first_pass = True
session = HTMLSession()
r = session.post(LOGIN_URL, {
'ww_x_username': ISA_USER,
'ww_x_password': ISA_PASS
})
print('Login state:', r)
logging.info('Login state: ' + str(r))
while True:
req = session.get(XML_URL)
pq = PyQuery(str(req.text.encode('utf-8')))
course = pq('itemPlan') \
.filter(lambda x, this: PyQuery(this).find('i_matiere').text() == COURSE_ID )
enrolled = course.find('cell') \
.filter(lambda x, this: PyQuery(this).find('c_variable').text() == 'NB_INSCRIT_SANS_MAX' ) \
.find('x_data') \
.text()
if first_pass:
print('Enrollemnt status:', enrolled)
print('Verifying notifications...')
notify()
print('The script is checking in a loop...')
first_pass = False
logging.info('Enrollemnt status: ' + str(enrolled))
if enrolled != 'cours complet':
print('New state', enrolled)
server = smtplib.SMTP('smtp.gmail.com', EMAIL_PORT)
server.ehlo()
server.starttls()
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
server.sendmail(EMAIL_ADDRESS, EMAIL_RECEIVER, EMAIL_MESSAGE)
server.close()
notify(50)
time.sleep(UPDATE_PERIOD)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment