Browse Source

various fixes
- make namesfile a csv (comma-sperated list rather than space-seperated)
- #! now specifies python3
- minor cleanup

Justin Tracey 6 years ago
parent
commit
663b5551c6
1 changed files with 12 additions and 15 deletions
  1. 12 15
      calendar.py

+ 12 - 15
calendar.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 from datetime import date,timedelta
 import sys
 import argparse
@@ -52,10 +52,12 @@ class CryspCalendar:
         for talk in practice:
             name = talk[0]
             day  = str_to_date(talk[1])
-            assert half or day not in practice_dict,\
-                "conflicting talks: %s and %s on %s" %\
-                (practice_dict[day][0], name, day)
-            if half:
+            if day in practice_dict:
+                assert half,\
+                    "conflicting talks: %s and %s on %s" %\
+                    (practice_dict[day][0], name, day)
+                practice_dict[day].append(name)
+            elif half:
                 practice_dict[day] = [name,]
             else:
                 practice_dict[day] = [name, ""]
@@ -66,7 +68,7 @@ class CryspCalendar:
         for note in notes:
             day     = str_to_date(note[1])
             message = note[2]
-            assert day not in notes_dict,\
+            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
@@ -87,16 +89,11 @@ class CryspCalendar:
                 'note "%s" designated on %s, which is not a meeting date' %\
                 (self.notes[day], day)
 
-    def pop_practice_talk(self, day, i):
-        if i < len(self.practice_talks[day]):
-            return self.practice_talks[day][i]
-        return None
-
     def pop_name(self, day, names, i):
         name = None
         if day in self.practice_talks:
-            #name = self.practice_talks[day][i]
-            name = self.pop_practice_talk(day, i)
+            if i < len(self.practice_talks[day]):
+                name = self.practice_talks[day][i]
         if name is None:
             constrained_names = (name for name in names \
                                  if name not in self.constraints \
@@ -163,7 +160,7 @@ def parse_constraintsfile(filename):
     f = open(filename, 'r')
     tweaks = {'c': [], 'p': [], 'h': [], 'n': []}
     for line in f:
-        l = line.rstrip().split(',')
+        l = [x.strip() for x in line.rstrip().split(',')]
         tweaks[l[0]].append(l[1:])
     return tweaks['c'], tweaks['p'], tweaks['h'], tweaks['n']
 
@@ -226,7 +223,7 @@ def main(argv=None):
 
     if args.namesfile:
         f = open(args.namesfile, 'r')
-        names = f.read().replace(",", " ").split()
+        names = [x.strip() for x in f.read().split(',')]
         f.close()
     else:
         names = args.names