#!/usr/bin/python2.7 # coding: utf8 import cgitb,cgi,re,sys,arrow from ics import Calendar,Event from urllib2 import urlopen # import requests def letsparse (info,formulaire): url = "https://planning-ade.umontpellier.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources="+info+"&projectId=54&calType=ical&nbWeeks="+formulaire.getvalue('duration') page = urlopen(url).read() line = page[0] if line == "<" : fichier2= open("./anticrash/"+info+'.ics','r') c = Calendar(fichier2.read().decode('utf8')) cestunbackup = 1 else : save=open("./anticrash/"+info+'.ics','w') save.write(page) c = Calendar(page.decode('utf8')) cestunbackup=0 printevent(c.events,cestunbackup,formulaire) return def printday(day): print("
") if day.format('ddd')=='Mon': print("Lundi ") elif day.format('ddd')=='Tue': print("Mardi ") elif day.format('ddd')=='Wed': print("Mercredi ") elif day.format('ddd')=='Thu': print("Jeudi ") elif day.format('ddd')=='Fri': print("Vendredi ") elif day.format('ddd')=='Sat': print("Samedi ") print(day.format('DD/MM')+"
") def printevent(eventpack, cestunbackup,formulaire): firstlaunch= True if formulaire.getvalue('noinfo')==None: print("

Info

Vous pouvez enregister cette page en favoris, pour être sûr de retrouver rapidement votre EDT

") if (cestunbackup==1): backup = u"

Info

L'EDT affiché actuellement est un backup ( le site de la fac semble etre down ): "+ eventpack[0].description[len(eventpack[0].description)-28:len(eventpack[0].description)-1]+ u"

" print(backup.encode('utf8')) for e in eventpack: pastevent=(e.end - arrow.utcnow()).total_seconds() if firstlaunch : previousend=e.end previousvisible=False oldday=e.begin.to('local').day firstlaunch=False elif (pastevent > 0) and (previousvisible) and (e.begin.to('local').day == oldday) and (firstlaunch==False) and ((e.begin - previousend).total_seconds() > 20*60): decalage = ((e.begin - previousend).total_seconds()/60)/30 for i in range(int(decalage)): print("
") previousend=e.end else : previousend=e.end if e.duration.total_seconds() == 3600+30*60: lg =1 elif e.duration.total_seconds() == 3600*3+15*60: lg=2 elif e.duration.total_seconds() == 3600*5: lg=3 else : lg=1 if (pastevent>0): if (e.begin.to('local').day != oldday) : if previousvisible==True: print('
') printday(e.begin.to('local')) print('
') oldday=e.begin.to('local').day previousvisible=True txt = u"

"+e.name+u"

" if lg > 1: txt=txt+u"


" if lg == 3 : txt+=u"


" txt=txt+u"

"+e.description[0:len(e.description)-30] if lg > 1: txt=txt+u"


" if lg == 3 : txt+=u"


" txt=txt+u"
"+e.location+u"
" print(txt.encode('utf8')) print(e.begin.to('local').format('DD/MM')+"
") print(e.begin.to('local').format('HH:mm')+" - "+e.end.to('local').format('HH:mm')) print(u"

") else : previousvisible=False cgitb.enable() print ('Content-type:text/html') print print (' ') formulaire = cgi.FieldStorage() if formulaire.getvalue('recherche')==None: print("") else : print(' Emploi du temps UM fds') fichier = open('edtnum','r') for line in fichier.readlines(): res= re.search('^([^:]*):'+formulaire.getvalue('recherche')+'$',line) if res: letsparse(res.group(1),formulaire) fichier.close() print('

Made by @Gaspard_c

')