2 Commits 5caf616723 ... ceb37164ec

Author SHA1 Message Date
  Justin Tracey ceb37164ec better invalid date error message 2 years ago
  Justin Tracey 66ded43202 fix off-by-one error with note parsing 2 years ago
1 changed files with 10 additions and 6 deletions
  1. 10 6
      vice-speaker-rotator.py

+ 10 - 6
vice-speaker-rotator.py

@@ -13,7 +13,11 @@ https://cs.uwaterloo.ca/twiki/view/CrySP/UpcomingEvents
 """
 
 def str_to_date(string_date):
-    return date(*[int(s) for s in string_date.split('-')])
+    try:
+        return date(*[int(s) for s in string_date.split('-')])
+    except:
+        print("invalid date: " + string_date)
+        sys.exit()
 
 class CryspCalendar:
     """Representation of a CrySP weekly meeting schedule for a term"""
@@ -27,8 +31,8 @@ class CryspCalendar:
         self.practice_talks.update(self.parse_practice_talks(half_practices,
                                                              half=True))
         self.notes      = self.parse_notes(notes)
-        self.notes.update(self.parse_notes(practice_talks))
-        self.notes.update(self.parse_notes(half_practices))
+        self.notes.update(self.parse_notes(map(lambda l:l[1:], practice_talks)))
+        self.notes.update(self.parse_notes(map(lambda l:l[1:], half_practices)))
         self.verify_constraints()
         self.no_repeat = no_repeat
 
@@ -86,11 +90,11 @@ class CryspCalendar:
     def parse_notes(self, notes):
         notes_dict = {}
         for note in notes:
-            day     = str_to_date(note[1])
-            message = note[2]
+            day     = str_to_date(note[0])
+            message = note[1]
             assert day not in notes_dict or notes_dict[day] == message,\
                 'conflicting notes: "%s" and "%s" on %s' %\
-                (notes_dict[day], message, note[1])
+                (notes_dict[day], message, note[0])
             notes_dict[day] = message
         return notes_dict