-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathefreicalendar.py
78 lines (54 loc) · 1.54 KB
/
efreicalendar.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import webapp2, logging
from google.appengine.api import urlfetch
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.write("Deployment successful!")
class CalendarHandler(webapp2.RequestHandler):
def get(self):
line_sep = '\r\n'
key = self.request.get("key")
defaultUrl = "http://extranet.groupe-efrei.fr/Student/OpenCalendar?key=";
if not key:
self.error(304)
calendarUrl = defaultUrl + key + "&langue=FR"
# get calendar from EFREI server
resp = urlfetch.fetch(calendarUrl);
calendar = resp.content
keywords = [
'BEGIN',
'METHOD',
'VERSION',
'PRODID',
'X-WR-TIMEZONE',
'X-WR-CALNAME',
'BEGIN',
'SUMMARY',
'DTSTART',
'DTEND',
'UID',
'DTSTAMP',
'END'
]
calendarLines = calendar.split(line_sep)
lineCount = len(calendarLines) - 1
while lineCount > 0:
line = calendarLines[lineCount]
colonIndex = line.find(':')
if colonIndex != -1:
lineKeyword = line[:colonIndex]
if lineKeyword == 'X-WR-CALNAME':
calendarLines[lineCount] = 'X-WR-CALNAME:EFREI by Tim'
elif lineKeyword == "PRODID":
calendarLines[lineCount] = "PRODID: Btimo"
if colonIndex == -1 or line[:colonIndex] not in keywords:
calendarLines.pop(lineCount)
lineCount -= 1
corrected = line_sep.join(calendarLines)
self.response.write(corrected);
self.response.headers['Content-type'] = 'text/plain; charset: utf-8'
app = webapp2.WSGIApplication([
('/', MainPage),
('/efrei_calendar', CalendarHandler)
], debug=True)