summaryrefslogtreecommitdiff
path: root/EDT STABLE/printedt.py
blob: 37a66be3cdb3fb073613048a841f810e35071a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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>')