diff --git a/parse.py b/parse.py index aef7c34..58fdef0 100755 --- a/parse.py +++ b/parse.py @@ -91,7 +91,6 @@ class TableHTMLParser(HTMLParser): # Inheritance def handle_starttag(self, tag, attrs): - #print("Encountered a start tag:", tag) if tag == 'table': self.table = [] elif tag == 'tr': @@ -109,7 +108,6 @@ class TableHTMLParser(HTMLParser): self.celly = int(attr[1]) def handle_endtag(self, tag): - #print("Encountered an end tag :", tag) if tag == 'table': self.endtable() elif tag == 'tr': @@ -118,7 +116,6 @@ class TableHTMLParser(HTMLParser): self.endcell() def handle_data(self, data): - #print("Encountered some data :", data) if self.iscell(): self.cell += data @@ -129,7 +126,8 @@ class Event: shortText = '' longText = '' date = False - slot = 0 + begSlot = 0 + endSlot = 0 # Generated data shortName = '' @@ -145,8 +143,11 @@ class Event: def feedLongText(self, longText): self.longText = longText - def feedSlot(self, slot): - self.slot = slot + def feedBegSlot(self, slot): + self.begSlot = slot + + def feedEndSlot(self, slot): + self.endSlot = slot def feedDate(self, date): self.date = date @@ -158,10 +159,10 @@ class Event: if self.longName: self.active = True - if self.date and isinstance(self.slot, int): - h, m = SLOTS[self.slot][0] + if self.date and isinstance(self.begSlot, int) and isinstance(self.endSlot, int): + h, m = SLOTS[self.begSlot][0] self.startTime = self.date + datetime.timedelta(hours=h, minutes=m) - h, m = SLOTS[self.slot][1] + h, m = SLOTS[self.endSlot][1] self.endTime = self.date + datetime.timedelta(hours=h, minutes=m) if self.longName: @@ -241,7 +242,6 @@ for line in tables[0]: # This is not a date, no data to grab here continue - print(line) for day in range(DAYS_PER_WEEK): date = day1date + datetime.timedelta(days=day) @@ -274,12 +274,23 @@ for line in tables[1]: # Feeding back time and slot to events events = [] for day in days: + prevEvent = False for slot in range(len(SLOTS)): event = days[day][slot] - event.feedDate(day) - event.feedSlot(slot) - event.endFeed() - events.append(event) + if prevEvent: + if prevEvent.shortText == event.shortText: + prevEvent.feedEndSlot(slot) + else: + prevEvent.endFeed() + events.append(prevEvent) + if not prevEvent or (prevEvent and prevEvent.shortText != event.shortText): + event.feedDate(day) + event.feedBegSlot(slot) + event.feedEndSlot(slot) + prevEvent = event + prevEvent.endFeed() + events.append(prevEvent) +print(287, len(events)) # Creating calendar cal = Calendar() -- libgit2 0.21.2