Commit 964ae38e93bb04a51f91765c07bd0cc5fc97ce9e

Authored by Geoffrey PREUD'HOMME
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
@@ -6,7 +6,7 @@ import datetime @@ -6,7 +6,7 @@ import datetime
6 import urllib.request 6 import urllib.request
7 from icalendar import Calendar 7 from icalendar import Calendar
8 from html.parser import HTMLParser 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 # Parse command line arguments 11 # Parse command line arguments
12 parser = argparse.ArgumentParser(description='Convertit l\'emploi du temps IMA en ICS') 12 parser = argparse.ArgumentParser(description='Convertit l\'emploi du temps IMA en ICS')
@@ -119,6 +119,9 @@ class TableHTMLParser(HTMLParser): @@ -119,6 +119,9 @@ class TableHTMLParser(HTMLParser):
119 if self.iscell(): 119 if self.iscell():
120 self.cell += data 120 self.cell += data
121 121
  122 +# TODO Use HTTP header date
  123 +UPDATE_TIME = datetime.datetime.now()
  124 +
122 # TODO Do something that really is OOP or do not... 125 # TODO Do something that really is OOP or do not...
123 126
124 class Event: 127 class Event:
@@ -175,17 +178,27 @@ class Event: @@ -175,17 +178,27 @@ class Event:
175 178
176 def __str__(self): 179 def __str__(self):
177 if self.active: 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 else: 182 else:
180 return 'Inactive event' 183 return 'Inactive event'
181 184
182 def getEvent(self): 185 def getEvent(self):
183 e = CalEvent() 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 e.add('summary', self.shortName) 195 e.add('summary', self.shortName)
185 e.add('description', self.longName) 196 e.add('description', self.longName)
186 e.add('dtstart', self.startTime) 197 e.add('dtstart', self.startTime)
187 e.add('dtend', self.endTime) 198 e.add('dtend', self.endTime)
188 e.add('location', self.location) 199 e.add('location', self.location)
  200 + e.add('last-modified', UPDATE_TIME)
  201 + e.add('dtstamp', UPDATE_TIME)
189 return e 202 return e
190 203
191 with urllib.request.urlopen(url) as handle: 204 with urllib.request.urlopen(url) as handle:
@@ -293,8 +306,10 @@ for day in days: @@ -293,8 +306,10 @@ for day in days:
293 306
294 # Creating calendar 307 # Creating calendar
295 cal = Calendar() 308 cal = Calendar()
296 -cal.add('proid', '-//Cours Polytech//mxm.dk//') 309 +cal.add('proid', '-//geoffrey.frogeye.fr//NONSGML Icalendar Calendar//EN')
297 cal.add('version', '2.0') 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 for event in events: 314 for event in events:
300 if event.active: 315 if event.active: