Commit 964ae38e93bb04a51f91765c07bd0cc5fc97ce9e
1 parent
7a72c101
Meilleur respect des standards iCal
Du moins selon Thunderbird. Pourrait peut-être permettre de résoudre le bug qui fait que lors d'une mise à jour, les évènement aparaissent brièvement en double sur pas mal d'applications de calendrier avant de revenir normal.
Showing
1 changed file
with
18 additions
and
3 deletions
Show diff stats
parse.py
... | ... | @@ -6,7 +6,7 @@ import datetime |
6 | 6 | import urllib.request |
7 | 7 | from icalendar import Calendar |
8 | 8 | from html.parser import HTMLParser |
9 | -from icalendar import Calendar, Event as CalEvent | |
9 | +from icalendar import vDatetime, Calendar, Event as CalEvent | |
10 | 10 | |
11 | 11 | # Parse command line arguments |
12 | 12 | parser = argparse.ArgumentParser(description='Convertit l\'emploi du temps IMA en ICS') |
... | ... | @@ -119,6 +119,9 @@ class TableHTMLParser(HTMLParser): |
119 | 119 | if self.iscell(): |
120 | 120 | self.cell += data |
121 | 121 | |
122 | +# TODO Use HTTP header date | |
123 | +UPDATE_TIME = datetime.datetime.now() | |
124 | + | |
122 | 125 | # TODO Do something that really is OOP or do not... |
123 | 126 | |
124 | 127 | class Event: |
... | ... | @@ -175,17 +178,27 @@ class Event: |
175 | 178 | |
176 | 179 | def __str__(self): |
177 | 180 | if self.active: |
178 | - return self.shortName+ ' [' + self.longName + '] ' + (str(self.startTime) + ' - ' + (str(self.endTime) + ' ') if self.startTime else '') + (('@ ' + self.location) if self.location else '') | |
181 | + return self.shortName + ' [' + self.longName + '] ' + (str(self.startTime) + ' - ' + (str(self.endTime) + ' ') if self.startTime else '') + (('@ ' + self.location) if self.location else '') | |
179 | 182 | else: |
180 | 183 | return 'Inactive event' |
181 | 184 | |
182 | 185 | def getEvent(self): |
183 | 186 | e = CalEvent() |
187 | + e.add('uid', '-'.join([ | |
188 | + 'polytech', | |
189 | + 'ima' + str(args.annee), | |
190 | + args.edt, | |
191 | + vDatetime(self.startTime).to_ical().decode(), | |
192 | + vDatetime(self.endTime).to_ical().decode(), | |
193 | + self.shortName | |
194 | + ])) | |
184 | 195 | e.add('summary', self.shortName) |
185 | 196 | e.add('description', self.longName) |
186 | 197 | e.add('dtstart', self.startTime) |
187 | 198 | e.add('dtend', self.endTime) |
188 | 199 | e.add('location', self.location) |
200 | + e.add('last-modified', UPDATE_TIME) | |
201 | + e.add('dtstamp', UPDATE_TIME) | |
189 | 202 | return e |
190 | 203 | |
191 | 204 | with urllib.request.urlopen(url) as handle: |
... | ... | @@ -293,8 +306,10 @@ for day in days: |
293 | 306 | |
294 | 307 | # Creating calendar |
295 | 308 | cal = Calendar() |
296 | -cal.add('proid', '-//Cours Polytech//mxm.dk//') | |
309 | +cal.add('proid', '-//geoffrey.frogeye.fr//NONSGML Icalendar Calendar//EN') | |
297 | 310 | cal.add('version', '2.0') |
311 | +cal.add('calscale', 'GREGORIAN') | |
312 | +cal.add('x-wr-calname', 'Polytech IMA ' + str(args.annee) + ' ' + args.edt) | |
298 | 313 | |
299 | 314 | for event in events: |
300 | 315 | if event.active: | ... | ... |