Commit 2ae9506d7efad1b0389663f482f22f8cb7e5c503

Authored by Geoffrey PREUD'HOMME
1 parent f6d0d112

Affiche les évènements buggués dans le tableau 2

Showing 1 changed file with 18 additions and 18 deletions   Show diff stats
parse.py
... ... @@ -36,7 +36,7 @@ elif args.annee == 4:
36 36 else:
37 37 raise ValueError('Année inconnue : ' + annee)
38 38  
39   -DAYS_PER_WEEK = 6
  39 +DAYS_PER_WEEK = 5.5
40 40  
41 41 TABLE_1_DATE_X = 1
42 42 TABLE_1_FIRST_SLOT_X = 2
... ... @@ -159,7 +159,7 @@ class Event:
159 159 self.shortName = self.shortText
160 160 self.longName = self.longText
161 161  
162   - if self.longName:
  162 + if self.shortName:
163 163 self.active = True
164 164  
165 165 if self.date and isinstance(self.begSlot, int) and isinstance(self.endSlot, int):
... ... @@ -250,25 +250,24 @@ days = dict()
250 250 # Parsing table 1
251 251 for line in tables[0]:
252 252 try:
253   - day1date = datetime.datetime.strptime(line[TABLE_1_DATE_X], DATE_FORMAT)
  253 + date = datetime.datetime.strptime(line[TABLE_1_DATE_X], DATE_FORMAT)
254 254 except (ValueError, TypeError):
255 255 # This is not a date, no data to grab here
256 256 continue
257 257  
258   - for day in range(DAYS_PER_WEEK):
259   - date = day1date + datetime.timedelta(days=day)
  258 + for weekSlot in range(int(DAYS_PER_WEEK * len(SLOTS))):
  259 + daySlot = weekSlot % len(SLOTS)
  260 +
  261 + # New day
  262 + if daySlot == 0:
  263 + if weekSlot != 0:
  264 + date = date + datetime.timedelta(days=1)
260 265  
261   - if date not in days:
262   - days[date] = [Event() for s in range(len(SLOTS))]
  266 + if date not in days:
  267 + days[date] = [Event() for s in range(len(SLOTS))]
263 268  
264   - for slot in range(len(SLOTS)):
265   - try:
266   - cell = line[day * len(SLOTS) + slot + TABLE_1_FIRST_SLOT_X]
267   - except IndexError:
268   - # Out of the table: saturday afternoon
269   - break
270   - days[date][slot].feedShortText(cell)
271   - continue
  269 + cell = line[TABLE_1_FIRST_SLOT_X + weekSlot]
  270 + days[date][daySlot].feedShortText(cell)
272 271  
273 272 # Parsing table 2
274 273 for line in tables[1]:
... ... @@ -290,13 +289,15 @@ for day in days:
290 289 prevEvent = False
291 290 for slot in range(len(SLOTS)):
292 291 event = days[day][slot]
  292 + sameAsPrevious = False
293 293 if prevEvent:
294   - if prevEvent.longText == event.longText:
  294 + sameAsPrevious = event.longText == prevEvent.longText if prevEvent.longText else event.shortText == prevEvent.shortText
  295 + if sameAsPrevious:
295 296 prevEvent.feedEndSlot(slot)
296 297 else:
297 298 prevEvent.endFeed()
298 299 events.append(prevEvent)
299   - if not prevEvent or (prevEvent and prevEvent.longText != event.longText):
  300 + if not prevEvent or (prevEvent and not sameAsPrevious):
300 301 event.feedDate(day)
301 302 event.feedBegSlot(slot)
302 303 event.feedEndSlot(slot)
... ... @@ -313,7 +314,6 @@ cal.add('x-wr-calname', 'Polytech IMA ' + str(args.annee) + ' ' + args.edt)
313 314  
314 315 for event in events:
315 316 if event.active:
316   - print(event, file=sys.stderr)
317 317 cal.add_component(event.getEvent())
318 318  
319 319 # Writing calendar to file
... ...