from requests import * import datetime import base64 payload = { 'action': 'login', 'username': "mollre", 'password': base64.b64decode(b"QW5uaWthMjU=").decode("utf-8"), #should be obfuscated } moodleLogin = "https://moodle2.dfg.fr.schule-bw.de/moodle/blocks/exa2fa/login/" iteration=1 table=[] aktuellerplan="" with session() as c: c.post(moodleLogin, data=payload) while "Fehler" not in aktuellerplan: if len(str(iteration))==1: tabelleurl = "https://moodle2.dfg.fr.schule-bw.de/moodle/pluginfile.php/7889/mod_resource/content/7/subst_00"+str(iteration)+".htm" else: tabelleurl = "https://moodle2.dfg.fr.schule-bw.de/moodle/pluginfile.php/7889/mod_resource/content/7/subst_0"+str(iteration)+".htm" iteration+=1 aktuellerplan = c.get(tabelleurl).text table.append(aktuellerplan) print("Download: "+"=="*iteration,end="\r") print("") print("Download finished") aktuellerplan=table[:-1] #Download of every part of the plan (saved as list) #The following basically is the concatenuation of the lsit into working html (small modifications) for i in range(len(aktuellerplan)-1): pos = aktuellerplan[i].index("")+8]+aktuellerplan[0][aktuellerplan[0].index("")+219:] aktuellerplan[0]=aktuellerplan[0][:aktuellerplan[0].index("\"mon_head\"")+21]+"

"+aktuellerplan[0][aktuellerplan[0].index("Runzstr. 83")+17:] aktuellerplan[0]=aktuellerplan[0][:aktuellerplan[0].index("tr.odd")+20]+" #ffffff"+aktuellerplan[0][aktuellerplan[0].index("tr.odd")+28:] aktuellerplan[0]=aktuellerplan[0][:aktuellerplan[0].index("tr.even")+21]+" #e3e3e3"+aktuellerplan[0][aktuellerplan[0].index("tr.even")+29:] #removal of UNTIS Text, saves space aktuellerplan[-1]=aktuellerplan[-1][:-285]+"

Last upload:"+str(datetime.datetime.now().time())+"

"+"" #optional, adds last upload time (for debugging?) weekdays=["Montag","Dienstag","Mittwoch","Donnerstag","Freitag"] for i in range(5): if weekdays[i] in aktuellerplan[0]: day=weekdays[i] try: nextday=weekdays[i+1] except: nextday=weekdays[0] #looks for Day in title (to determine the number of elements for th 1rst and 2nd table) aktuellerplan[0]=aktuellerplan[0][:-8] #removing additional content (useful?) try: lenght_of_1st_day = int(aktuellerplan[0][aktuellerplan[0].index(day)+len(day)+21]) except: lenght_of_1st_day = 1 #tries to determine lenght of 1rst day, might crash if >10 (2 digits), couldn't try it... for i in range(lenght_of_1st_day-1): aktuellerplan[i+1]=aktuellerplan[i+1][aktuellerplan[i+1].index("mon_title"):] aktuellerplan[i+1]=aktuellerplan[i+1][aktuellerplan[i+1].index("mon_list")+397:] if i>0: aktuellerplan[i]=aktuellerplan[i][:aktuellerplan[i].index("/table")-1] tabletext="" for i in range(lenght_of_1st_day): tabletext=tabletext+aktuellerplan[0] del aktuellerplan[0] #puts the LE of 1rst day onto 1 table + puts them into 1 html for i in range(len(aktuellerplan)-1): aktuellerplan[i+1]=aktuellerplan[i+1][aktuellerplan[i+1].index("mon_title"):] aktuellerplan[i+1]=aktuellerplan[i+1][aktuellerplan[i+1].index("mon_list")+397:] if i==0: aktuellerplan[i]=aktuellerplan[i][:-8] elif i>0: aktuellerplan[i]=aktuellerplan[i][:aktuellerplan[i].index("/table")-1] #same for 2nd day for x in aktuellerplan: tabletext=tabletext+x try: tabletext=tabletext[:tabletext.index("1 / ")-7]+tabletext[tabletext.index("1 / ")+6:] except: print("1 page for day1") try: tabletext=tabletext[:tabletext.index("1 / ")-7]+tabletext[tabletext.index("1 / ")+6:] except: print("1 page for day2") #removes title showing (Tag1/X) if nextday not in tabletext: nextday=weekdays[0] #nextday = daynow+1, but that won't work for vacations. This fixes the issue (assuming school starts on monday afterwards) tabletext=tabletext[:tabletext.index("tr.even")+32]+"\ntd.list{width:14%;}"+tabletext[tabletext.index("tr.even")+32:] tabletext=tabletext[:tabletext.index("
")]+"
"+tabletext[tabletext.index("
"):] tabletext=tabletext[:tabletext.index(nextday)-34]+"
"+tabletext[tabletext.index(nextday)-34:] tabletext=tabletext[:tabletext.index("
"+tabletext[tabletext.index("","") tabletext=tabletext.replace("
","") #removes center-tags bc they distort the layout of the table js_func="""""" tabletext = tabletext[:tabletext.index("")]+js_func+tabletext[tabletext.index(""):] tabletext = tabletext[:tabletext.index("")]+""+tabletext[tabletext.index(""):] #adds js function for autoscroll (up and down) #REQUIRES JQUERY tabletext = tabletext[:tabletext.index("")+6]+tabletext[tabletext.index("Stand"):tabletext.index("Stand")+23]+tabletext[tabletext.index("Stand")+65:] #removes some faulty div/span content (was useless anyways) tabletext = tabletext.replace("margin: 0;","text-align: center;") tabletext = tabletext[:tabletext.index("table.info")+13]+" margin:auto;"+tabletext[tabletext.index("table.info")+13:] #centers title of day print("Conversion finished, Writing file") with open("index.html","w") as f: f.write(tabletext) #alternatively: upload to FTP?