summaryrefslogtreecommitdiff
path: root/EDT STABLE/printedt.py
diff options
context:
space:
mode:
Diffstat (limited to 'EDT STABLE/printedt.py')
-rw-r--r--EDT STABLE/printedt.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/EDT STABLE/printedt.py b/EDT STABLE/printedt.py
new file mode 100644
index 0000000..37a66be
--- /dev/null
+++ b/EDT STABLE/printedt.py
@@ -0,0 +1,74 @@
+#!/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,nbweeks):
+ url = "https://planning-ade.umontpellier.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources="+info+"&projectId=54&calType=ical&nbWeeks="+nbweeks
+ 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)
+ return
+def printday(day):
+ print("<div class='cadreday'><div class='day'>"+ day.format('DD/MM')+"</div></div>")
+
+def printevent(eventpack, cestunbackup):
+ oldday = 0
+ 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:
+ if e.duration.total_seconds() == 3600*1+30*60:
+ lg =0
+ elif e.duration.total_seconds() == 3600*3+15*60:
+ lg=1
+ elif e.duration.total_seconds() == 3600*5:
+ lg=2
+ else :
+ lg=0
+ if (e.begin.to('local').day != oldday) :
+ printday(e.begin.to('local'))
+ oldday=e.begin.to('local').day
+ txt = u"<div class='cadre'><div class='event'><h2>"+e.name+u"</h2>"
+ if lg > 0:
+ txt=txt+u"<br><br><br>"
+ if lg == 2 :
+ txt+=u"<br><br><br>"
+ txt=txt+u"<p>"+e.description[0:len(e.description)-30]
+ if lg > 0:
+ txt=txt+u"<br><br><br>"
+ if lg == 2 :
+ 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 HH:mm')+"<br>")
+ print(u"</p></div></div>")
+
+
+cgitb.enable()
+print ('Content-type:text/html')
+print
+print ('<!doctype html><html lang="fr"> <head>')
+formulaire = cgi.FieldStorage()
+if formulaire.getvalue('recherche')==None:
+ print("<meta http-equiv='refresh' content='1; URL=index.py'>")
+else :
+ print('<meta charset="utf-8"><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.getvalue('duration'))
+ fichier.close()
+ print('<p> Made by <a href="https://twitter.com/Gaspard_c">@Gaspard_c</a></p></body></html>')