From 2ae9506d7efad1b0389663f482f22f8cb7e5c503 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 25 Nov 2016 07:26:30 +0100 Subject: [PATCH] Affiche les évènements buggués dans le tableau 2 --- parse.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/parse.py b/parse.py index 642127f..c11bd8b 100755 --- a/parse.py +++ b/parse.py @@ -36,7 +36,7 @@ elif args.annee == 4: else: raise ValueError('Année inconnue : ' + annee) -DAYS_PER_WEEK = 6 +DAYS_PER_WEEK = 5.5 TABLE_1_DATE_X = 1 TABLE_1_FIRST_SLOT_X = 2 @@ -159,7 +159,7 @@ class Event: self.shortName = self.shortText self.longName = self.longText - if self.longName: + if self.shortName: self.active = True if self.date and isinstance(self.begSlot, int) and isinstance(self.endSlot, int): @@ -250,25 +250,24 @@ days = dict() # Parsing table 1 for line in tables[0]: try: - day1date = datetime.datetime.strptime(line[TABLE_1_DATE_X], DATE_FORMAT) + date = datetime.datetime.strptime(line[TABLE_1_DATE_X], DATE_FORMAT) except (ValueError, TypeError): # This is not a date, no data to grab here continue - for day in range(DAYS_PER_WEEK): - date = day1date + datetime.timedelta(days=day) + for weekSlot in range(int(DAYS_PER_WEEK * len(SLOTS))): + daySlot = weekSlot % len(SLOTS) + + # New day + if daySlot == 0: + if weekSlot != 0: + date = date + datetime.timedelta(days=1) - if date not in days: - days[date] = [Event() for s in range(len(SLOTS))] + if date not in days: + days[date] = [Event() for s in range(len(SLOTS))] - for slot in range(len(SLOTS)): - try: - cell = line[day * len(SLOTS) + slot + TABLE_1_FIRST_SLOT_X] - except IndexError: - # Out of the table: saturday afternoon - break - days[date][slot].feedShortText(cell) - continue + cell = line[TABLE_1_FIRST_SLOT_X + weekSlot] + days[date][daySlot].feedShortText(cell) # Parsing table 2 for line in tables[1]: @@ -290,13 +289,15 @@ for day in days: prevEvent = False for slot in range(len(SLOTS)): event = days[day][slot] + sameAsPrevious = False if prevEvent: - if prevEvent.longText == event.longText: + sameAsPrevious = event.longText == prevEvent.longText if prevEvent.longText else event.shortText == prevEvent.shortText + if sameAsPrevious: prevEvent.feedEndSlot(slot) else: prevEvent.endFeed() events.append(prevEvent) - if not prevEvent or (prevEvent and prevEvent.longText != event.longText): + if not prevEvent or (prevEvent and not sameAsPrevious): event.feedDate(day) event.feedBegSlot(slot) event.feedEndSlot(slot) @@ -313,7 +314,6 @@ cal.add('x-wr-calname', 'Polytech IMA ' + str(args.annee) + ' ' + args.edt) for event in events: if event.active: - print(event, file=sys.stderr) cal.add_component(event.getEvent()) # Writing calendar to file -- libgit2 0.21.2