From f63e7370340a7381cdc1ea8edfe18d494a4b50a7 Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:10:56 +0200 Subject: Initial commit --- EDT STABLE/printedt.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 EDT STABLE/printedt.py (limited to 'EDT STABLE/printedt.py') 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("
"+ day.format('DD/MM')+"
") + +def printevent(eventpack, cestunbackup): + oldday = 0 + 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: + 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"

"+e.name+u"

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


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


" + txt=txt+u"

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


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


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

") + + +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.getvalue('duration')) + fichier.close() + print('

Made by @Gaspard_c

') -- cgit v1.2.3