From f6d0d112201dbeaaeb3f48222adb1ab58f875f29 Mon Sep 17 00:00:00 2001
From: Geoffrey Frogeye <geoffrey@frogeye.fr>
Date: Mon, 21 Nov 2016 07:34:09 +0100
Subject: [PATCH] Meilleur respect des standards iCal

---
 parse.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/parse.py b/parse.py
index 0d9b4fd..642127f 100755
--- a/parse.py
+++ b/parse.py
@@ -6,7 +6,7 @@ import datetime
 import urllib.request
 from icalendar import Calendar
 from html.parser import HTMLParser
-from icalendar import Calendar, Event as CalEvent
+from icalendar import vDatetime, Calendar, Event as CalEvent
 
 # Parse command line arguments
 parser = argparse.ArgumentParser(description='Convertit l\'emploi du temps IMA en ICS')
@@ -119,6 +119,9 @@ class TableHTMLParser(HTMLParser):
         if self.iscell():
             self.cell += data
 
+# TODO Use HTTP header date
+UPDATE_TIME = datetime.datetime.now()
+
 # TODO Do something that really is OOP or do not...
 
 class Event:
@@ -175,17 +178,27 @@ class Event:
 
     def __str__(self):
         if self.active:
-            return self.shortName+ ' [' + self.longName + '] ' + (str(self.startTime) + ' - ' + (str(self.endTime) + ' ') if self.startTime else '') + (('@ ' + self.location) if self.location else '')
+            return self.shortName + ' [' + self.longName + '] ' + (str(self.startTime) + ' - ' + (str(self.endTime) + ' ') if self.startTime else '') + (('@ ' + self.location) if self.location else '')
         else:
             return 'Inactive event'
 
     def getEvent(self):
         e = CalEvent()
+        e.add('uid', '-'.join([
+            'polytech',
+            'ima' + str(args.annee),
+            args.edt,
+            vDatetime(self.startTime).to_ical().decode(),
+            vDatetime(self.endTime).to_ical().decode(),
+            self.shortName
+        ]))
         e.add('summary', self.shortName)
         e.add('description', self.longName)
         e.add('dtstart', self.startTime)
         e.add('dtend', self.endTime)
         e.add('location', self.location)
+        e.add('last-modified', UPDATE_TIME)
+        e.add('dtstamp', UPDATE_TIME)
         return e
 
 with urllib.request.urlopen(url) as handle:
@@ -293,8 +306,10 @@ for day in days:
 
 # Creating calendar
 cal = Calendar()
-cal.add('proid', '-//Cours Polytech//mxm.dk//')
+cal.add('proid', '-//geoffrey.frogeye.fr//NONSGML Icalendar Calendar//EN')
 cal.add('version', '2.0')
+cal.add('calscale', 'GREGORIAN')
+cal.add('x-wr-calname', 'Polytech IMA ' + str(args.annee) + ' ' + args.edt)
 
 for event in events:
     if event.active:
--
libgit2 0.21.2