Browse Source

add support for date ranges in constraints

Justin Tracey 3 years ago
parent
commit
5c522173fd
1 changed files with 15 additions and 6 deletions
  1. 15 6
      vice-speaker-rotator.py

+ 15 - 6
vice-speaker-rotator.py

@@ -55,8 +55,16 @@ class CryspCalendar:
             date_strs = constraint[1:]
             dates     = []
             for date_str in date_strs:
-                dates.append(str_to_date(date_str))
-                constraint_dict[name] = dates
+                if '--' in date_str:
+                    #date_range = list(map(str_to_date, date_str.split('--')))
+                    date_range = date_str.split('--')
+                    date_range = [str_to_date(date_range[0]),
+                                  str_to_date(date_range[1])]
+                    [dates.append(d) for d in self.dates \
+                     if date_range[0] <= d <= date_range[1]]
+                else:
+                    dates.append(str_to_date(date_str))
+            constraint_dict[name] = dates
         return constraint_dict
 
     def parse_practice_talks(self, practice, half=False):
@@ -181,14 +189,15 @@ def parse_constraintsfile(filename):
         return tweaks['c'], tweaks['p'], tweaks['h'], tweaks['n']
 
 def make_parser():
-    parser = argparse.ArgumentParser(description =
-        'Print a speaker schedule for the CrySP weekly meetings.',
+    parser = argparse.ArgumentParser(description ='''\
+Print a speaker schedule for the CrySP weekly meetings.
+All dates are ISO formatted (yyyy-mm-dd). Constraints in the constraints file
+can also be ranges of ISO formatted dates (yyyy-mm-dd--yyyy-mm-dd).''',
         formatter_class=RawTextHelpFormatter)
     parser.add_argument('-s', '--start',
                         metavar = 'DATE', required = True,
                         help =
-                        'date of the first meeting in ISO format\n' +\
-                        '(yyyy-mm-dd)')
+                        'date of the first meeting')
     parser.add_argument('-e', '--end', metavar = 'DATE',
                         help =
                         'last date to schedule a meeting on or before\n' +\