Commit 359563ab72c4d2860dd78e034ff6efcb0a4bf1b9

Authored by Geoffrey PREUD'HOMME
1 parent 871bc6d6

Support de la date de modification

Showing 1 changed file with 4 additions and 5 deletions   Show diff stats
@@ -4,6 +4,7 @@ import sys @@ -4,6 +4,7 @@ import sys
4 import argparse 4 import argparse
5 import datetime 5 import datetime
6 import urllib.request 6 import urllib.request
  7 +import dateutil.parser
7 from icalendar import Calendar 8 from icalendar import Calendar
8 from html.parser import HTMLParser 9 from html.parser import HTMLParser
9 from icalendar import vDatetime, Calendar, Event as CalEvent 10 from icalendar import vDatetime, Calendar, Event as CalEvent
@@ -119,9 +120,6 @@ class TableHTMLParser(HTMLParser): @@ -119,9 +120,6 @@ class TableHTMLParser(HTMLParser):
119 if self.iscell(): 120 if self.iscell():
120 self.cell += data 121 self.cell += data
121 122
122 -# TODO Use HTTP header date  
123 -UPDATE_TIME = datetime.datetime.now()  
124 -  
125 # TODO Do something that really is OOP or do not... 123 # TODO Do something that really is OOP or do not...
126 124
127 class Event: 125 class Event:
@@ -197,11 +195,12 @@ class Event: @@ -197,11 +195,12 @@ class Event:
197 e.add('dtstart', self.startTime) 195 e.add('dtstart', self.startTime)
198 e.add('dtend', self.endTime) 196 e.add('dtend', self.endTime)
199 e.add('location', self.location) 197 e.add('location', self.location)
200 - e.add('last-modified', UPDATE_TIME)  
201 - e.add('dtstamp', UPDATE_TIME) 198 + e.add('last-modified', updateTime)
  199 + e.add('dtstamp', updateTime)
202 return e 200 return e
203 201
204 with urllib.request.urlopen(url) as handle: 202 with urllib.request.urlopen(url) as handle:
  203 + updateTime = dateutil.parser.parse(handle.headers['Last-Modified'])
205 htmlStr = handle.read().decode('iso-8859-15') 204 htmlStr = handle.read().decode('iso-8859-15')
206 205
207 # Read HTML tables 206 # Read HTML tables