Created
September 24, 2021 10:56
-
-
Save bostrot/db742e6af7dda0fcd1a04bee38f6407c to your computer and use it in GitHub Desktop.
FH Aachen Grade checker for QIS with telegram notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# FH Aachen Selenium Grade Checker with Telegram Send for notifications | |
# Description: Setup telegram-send first with pip3 install telegram_send and then in bash: telegram-send --configure | |
# Automate with cron e.g.: crontab -e and enter 0 */12 * * * /usr/bin/python3 /path/to/check_grades.py For every 12h. | |
# Author: Eric Trenkel (@bostrot) | |
# License: MIT | |
### | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
import telegram_send | |
chrome_options = Options() | |
chrome_options.add_argument('--headless') | |
chrome_options.add_argument('--no-sandbox') | |
chrome_options.add_argument('--disable-dev-shm-usage') | |
driver = webdriver.Chrome(options=chrome_options) | |
# go to qis site | |
def openSite(): | |
driver.get('https://qis.fh-aachen.de/') | |
# authenticate | |
def login(): | |
driver.find_element_by_id('asdf').send_keys('USER') | |
driver.find_element_by_id('fdsa').send_keys('PASSWORD') | |
driver.find_element_by_id('loginForm:login').click() | |
# navigate to grades | |
def navToGrades(): | |
driver.find_element_by_xpath('//*[contains(text(), \'Notenspiegel\')]').click() | |
driver.find_element_by_css_selector('a[title*=\'Informatik\']').click() | |
# get credits | |
def getCredits(): | |
ects = driver.find_element_by_xpath('//*[contains(text(), \'ECTS-Konto Sem 1-5 IBP\')]') | |
ects = ects.find_element_by_xpath('..') # parent | |
ects = ects.find_elements_by_css_selector('td') | |
if ects[5].text != '47': | |
print('ECTS changed to ' + ects[5].text) | |
# print an array | |
def printTable(element): | |
moduleText = 'New grade:\n' | |
for i in range(len(element)): | |
print(element[i].text) | |
moduleText += element[i].text + '\n' | |
try: | |
telegram_send.send(messages=[moduleText]) | |
except Exception as e: | |
print('Unable to send', e) | |
# check for specific modules | |
def checkModule(): | |
tables = driver.find_elements_by_css_selector('tr') | |
f = open('cache.txt', 'r') | |
cache = f.read() | |
for i in range(len(tables)): | |
table = tables[i].find_elements_by_css_selector('td') | |
if (len(table) < 1): | |
continue | |
table = table[0] | |
if table.text not in cache: | |
print('Found new module:\n') | |
temp = table.find_element_by_xpath('..').find_elements_by_css_selector('td') | |
printTable(temp) | |
f = open('cache.txt', 'a') | |
f.write(table.text + '\n') | |
f.close() | |
# save screenshot | |
def createScreenshot(): | |
driver.get_screenshot_as_file('screen.png') | |
# main | |
try: | |
openSite() | |
login() | |
navToGrades() | |
getCredits() | |
checkModule() | |
driver.quit() | |
except Exception as e: | |
print(e) | |
finally: | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment