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
@@ -91,7 +91,6 @@ class TableHTMLParser(HTMLParser): @@ -91,7 +91,6 @@ class TableHTMLParser(HTMLParser):
91 91
92 # Inheritance 92 # Inheritance
93 def handle_starttag(self, tag, attrs): 93 def handle_starttag(self, tag, attrs):
94 - #print("Encountered a start tag:", tag)  
95 if tag == 'table': 94 if tag == 'table':
96 self.table = [] 95 self.table = []
97 elif tag == 'tr': 96 elif tag == 'tr':
@@ -109,7 +108,6 @@ class TableHTMLParser(HTMLParser): @@ -109,7 +108,6 @@ class TableHTMLParser(HTMLParser):
109 self.celly = int(attr[1]) 108 self.celly = int(attr[1])
110 109
111 def handle_endtag(self, tag): 110 def handle_endtag(self, tag):
112 - #print("Encountered an end tag :", tag)  
113 if tag == 'table': 111 if tag == 'table':
114 self.endtable() 112 self.endtable()
115 elif tag == 'tr': 113 elif tag == 'tr':
@@ -118,7 +116,6 @@ class TableHTMLParser(HTMLParser): @@ -118,7 +116,6 @@ class TableHTMLParser(HTMLParser):
118 self.endcell() 116 self.endcell()
119 117
120 def handle_data(self, data): 118 def handle_data(self, data):
121 - #print("Encountered some data :", data)  
122 if self.iscell(): 119 if self.iscell():
123 self.cell += data 120 self.cell += data
124 121
@@ -129,7 +126,8 @@ class Event: @@ -129,7 +126,8 @@ class Event:
129 shortText = '' 126 shortText = ''
130 longText = '' 127 longText = ''
131 date = False 128 date = False
132 - slot = 0 129 + begSlot = 0
  130 + endSlot = 0
133 131
134 # Generated data 132 # Generated data
135 shortName = '' 133 shortName = ''
@@ -145,8 +143,11 @@ class Event: @@ -145,8 +143,11 @@ class Event:
145 def feedLongText(self, longText): 143 def feedLongText(self, longText):
146 self.longText = longText 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 def feedDate(self, date): 152 def feedDate(self, date):
152 self.date = date 153 self.date = date
@@ -158,10 +159,10 @@ class Event: @@ -158,10 +159,10 @@ class Event:
158 if self.longName: 159 if self.longName:
159 self.active = True 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 self.startTime = self.date + datetime.timedelta(hours=h, minutes=m) 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 self.endTime = self.date + datetime.timedelta(hours=h, minutes=m) 166 self.endTime = self.date + datetime.timedelta(hours=h, minutes=m)
166 167
167 if self.longName: 168 if self.longName:
@@ -241,7 +242,6 @@ for line in tables[0]: @@ -241,7 +242,6 @@ for line in tables[0]:
241 # This is not a date, no data to grab here 242 # This is not a date, no data to grab here
242 continue 243 continue
243 244
244 - print(line)  
245 for day in range(DAYS_PER_WEEK): 245 for day in range(DAYS_PER_WEEK):
246 date = day1date + datetime.timedelta(days=day) 246 date = day1date + datetime.timedelta(days=day)
247 247
@@ -274,12 +274,23 @@ for line in tables[1]: @@ -274,12 +274,23 @@ for line in tables[1]:
274 # Feeding back time and slot to events 274 # Feeding back time and slot to events
275 events = [] 275 events = []
276 for day in days: 276 for day in days:
  277 + prevEvent = False
277 for slot in range(len(SLOTS)): 278 for slot in range(len(SLOTS)):
278 event = days[day][slot] 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 # Creating calendar 295 # Creating calendar
285 cal = Calendar() 296 cal = Calendar()