diff options
| author | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:10:56 +0200 |
|---|---|---|
| committer | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:10:56 +0200 |
| commit | f63e7370340a7381cdc1ea8edfe18d494a4b50a7 (patch) | |
| tree | db93d3458c065da1d7d3507e28a30bc603f1d46c /EDT/printedt.py | |
Initial commit
Diffstat (limited to 'EDT/printedt.py')
| -rw-r--r-- | EDT/printedt.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/EDT/printedt.py b/EDT/printedt.py new file mode 100644 index 0000000..8ebc9b3 --- /dev/null +++ b/EDT/printedt.py @@ -0,0 +1,109 @@ +#!/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("<div class='cadreday'><div class='day'>") + 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')+"</div></div>") + +def printevent(eventpack, cestunbackup,formulaire): + firstlaunch= True + if formulaire.getvalue('noinfo')==None: + print("<div class='cadreinfo'><div class='info'><h2>Info</h2><p> Vous pouvez enregister cette page en favoris, pour être sûr de retrouver rapidement votre EDT</p></div></div>") + if (cestunbackup==1): + backup = u"<div class='cadreinfo'><div class='info'><h2>Info</h2> <p> 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"</p></div></div>" + 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("<br>") + 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('<br>') + printday(e.begin.to('local')) + print('<br>') + oldday=e.begin.to('local').day + previousvisible=True + txt = u"<div class='cadre'><div class='event'><h2>"+e.name+u"</h2>" + if lg > 1: + txt=txt+u"<br><br><br>" + if lg == 3 : + txt+=u"<br><br><br>" + txt=txt+u"<p>"+e.description[0:len(e.description)-30] + if lg > 1: + txt=txt+u"<br><br><br>" + if lg == 3 : + txt+=u"<br><br><br>" + txt=txt+u"<br>"+e.location+u"<br>" + print(txt.encode('utf8')) + print(e.begin.to('local').format('DD/MM')+"<br>") + print(e.begin.to('local').format('HH:mm')+" - "+e.end.to('local').format('HH:mm')) + print(u"</p></div></div>") + else : + previousvisible=False + + +cgitb.enable() +print ('Content-type:text/html') +print +print ('<!doctype html><html lang="fr"> <head><meta name="viewport" content="width=device-width"/>') +formulaire = cgi.FieldStorage() +if formulaire.getvalue('recherche')==None: + print("<meta http-equiv='refresh' content='0; URL=index.py'>") +else : + print('<meta charset="utf-8"><link rel="stylesheet" media="handheld" href="style.css" type="text/css" /><link rel="stylesheet" type="text/css" href="style.css"><title> Emploi du temps UM fds</title></head><body>') + 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('<p> Made by <a href="https://twitter.com/Gaspard_c">@Gaspard_c</a></p></body></html>') |
