Commit ab9e873d78b4824a7f47282683d28c74a7aa41d5

Authored by Geoffrey PREUD'HOMME
1 parent 3e3f7292

No longer cut lessons by hour

Showing 1 changed file with 25 additions and 14 deletions   Show diff stats
parse.py
... ... @@ -91,7 +91,6 @@ class TableHTMLParser(HTMLParser):
91 91  
92 92 # Inheritance
93 93 def handle_starttag(self, tag, attrs):
94   - #print("Encountered a start tag:", tag)
95 94 if tag == 'table':
96 95 self.table = []
97 96 elif tag == 'tr':
... ... @@ -109,7 +108,6 @@ class TableHTMLParser(HTMLParser):
109 108 self.celly = int(attr[1])
110 109  
111 110 def handle_endtag(self, tag):
112   - #print("Encountered an end tag :", tag)
113 111 if tag == 'table':
114 112 self.endtable()
115 113 elif tag == 'tr':
... ... @@ -118,7 +116,6 @@ class TableHTMLParser(HTMLParser):
118 116 self.endcell()
119 117  
120 118 def handle_data(self, data):
121   - #print("Encountered some data :", data)
122 119 if self.iscell():
123 120 self.cell += data
124 121  
... ... @@ -129,7 +126,8 @@ class Event:
129 126 shortText = ''
130 127 longText = ''
131 128 date = False
132   - slot = 0
  129 + begSlot = 0
  130 + endSlot = 0
133 131  
134 132 # Generated data
135 133 shortName = ''
... ... @@ -145,8 +143,11 @@ class Event:
145 143 def feedLongText(self, longText):
146 144 self.longText = longText
147 145  
148   - def feedSlot(self, slot):
149   - self.slot = slot
  146 + def feedBegSlot(self, slot):
  147 + self.begSlot = slot
  148 +
  149 + def feedEndSlot(self, slot):
  150 + self.endSlot = slot
150 151  
151 152 def feedDate(self, date):
152 153 self.date = date
... ... @@ -158,10 +159,10 @@ class Event:
158 159 if self.longName:
159 160 self.active = True
160 161  
161   - if self.date and isinstance(self.slot, int):
162   - h, m = SLOTS[self.slot][0]
  162 + if self.date and isinstance(self.begSlot, int) and isinstance(self.endSlot, int):
  163 + h, m = SLOTS[self.begSlot][0]
163 164 self.startTime = self.date + datetime.timedelta(hours=h, minutes=m)
164   - h, m = SLOTS[self.slot][1]
  165 + h, m = SLOTS[self.endSlot][1]
165 166 self.endTime = self.date + datetime.timedelta(hours=h, minutes=m)
166 167  
167 168 if self.longName:
... ... @@ -241,7 +242,6 @@ for line in tables[0]:
241 242 # This is not a date, no data to grab here
242 243 continue
243 244  
244   - print(line)
245 245 for day in range(DAYS_PER_WEEK):
246 246 date = day1date + datetime.timedelta(days=day)
247 247  
... ... @@ -274,12 +274,23 @@ for line in tables[1]:
274 274 # Feeding back time and slot to events
275 275 events = []
276 276 for day in days:
  277 + prevEvent = False
277 278 for slot in range(len(SLOTS)):
278 279 event = days[day][slot]
279   - event.feedDate(day)
280   - event.feedSlot(slot)
281   - event.endFeed()
282   - events.append(event)
  280 + if prevEvent:
  281 + if prevEvent.shortText == event.shortText:
  282 + prevEvent.feedEndSlot(slot)
  283 + else:
  284 + prevEvent.endFeed()
  285 + events.append(prevEvent)
  286 + if not prevEvent or (prevEvent and prevEvent.shortText != event.shortText):
  287 + event.feedDate(day)
  288 + event.feedBegSlot(slot)
  289 + event.feedEndSlot(slot)
  290 + prevEvent = event
  291 + prevEvent.endFeed()
  292 + events.append(prevEvent)
  293 +print(287, len(events))
283 294  
284 295 # Creating calendar
285 296 cal = Calendar()
... ...