summaryrefslogtreecommitdiff
path: root/EDT/printedt.py
blob: 8ebc9b305a281a9b53ea29341467e6529513ba00 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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>')