Skip to content

Instantly share code, notes, and snippets.

@Spotlight0xff
Created November 29, 2016 21:51
Show Gist options
  • Save Spotlight0xff/7824dcf72d6930e59ceefdb2c874782c to your computer and use it in GitHub Desktop.
Save Spotlight0xff/7824dcf72d6930e59ceefdb2c874782c to your computer and use it in GitHub Desktop.
Homework check
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
from os.path import isfile
SP_KEY = '' # change to SimplePush.io key
SP_URL = 'https://api.simplepush.io/send'
def send_sp(title, msg):
r = requests.post(SP_URL, {
'key': SP_KEY,
'title': title,
'msg': msg
})
print('SimplePush: {} returned {}'.format(title, r.status_code))
def write_file(path, content):
with open(path, 'w') as f:
f.write(str(content))
tkm_addr = "http://www.tkm.kit.edu/lehre/3161_3174.php" # adress for TKM homework
ttp_addr = "https://www.itp.kit.edu/~sekulla/ETTP/pdf/" # adress for TTP homework
req_tkm = requests.get(tkm_addr)
req_ttp = requests.get(ttp_addr)
if req_tkm.status_code != 200:
logger.critical('failed to get tkm homework')
quit()
if req_ttp.status_code != 200:
logger.critical('failed to get ttp homework')
quit()
tkm_current = BeautifulSoup(req_tkm.content, 'lxml')
ttp_current = BeautifulSoup(req_ttp.content, 'lxml')
#print tkm_current
ttp_current_text = ttp_current.find_all("table")[0]
tkm_current_text = tkm_current.find_all("div", class_="text")[1]
exercises = [('TKM', 'tkm.txt', tkm_current_text, tkm_addr), ('TTP', 'ttp.txt', ttp_current_text, ttp_addr)]
for title, path, current_text, addr in exercises:
if not isfile(path):
write_file(path, current_text)
else:
with open(path, 'r') as f:
if str(current_text) != f.read():
write_file(path, current_text)
send_sp("Neues {}-Blatt!".format(title), addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment