diff options
author | rsiddharth <rsd@gnu.org> | 2016-03-15 23:31:16 -0400 |
---|---|---|
committer | rsiddharth <rsd@gnu.org> | 2016-03-15 23:31:16 -0400 |
commit | 7f6af7acf2bdeb216ed6db847d98eeaf13326010 (patch) | |
tree | a1c4b3f0d96c2c57fde4ce27f16764f9105e18ab /lps_gen.py | |
parent | d17f9e74e4d409fb9f07cfd38c956d6b9af7f43c (diff) |
Add LPiCal class
Contains two methods at the moment:
- get_timeslot
- get_month_day
Addresses issue #8.
Diffstat (limited to 'lps_gen.py')
-rw-r--r-- | lps_gen.py | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -19,6 +19,7 @@ # <http://www.gnu.org/licenses/>. import json +import re import sys from argparse import ArgumentParser @@ -102,6 +103,44 @@ def json_read(filename): object_pairs_hook=OrderedDict) +class LPiCal(object): + """ + Used for producing iCal for LP schedule. + """ + + def __init__(self, lps_dict): + self.lps_dict = lps_dict + + # Matches strings like '09:45 - 10:30: Lorem ipsum dolor sit.' + self.timeslot_re = re.compile(r'(\d+:\d+).+?(\d+:\d+)') + # Matches strings like 'Saturday, March 19' + self.month_day_re = re.compile(r'\w+,\s*([a-zA-Z]+)\s*(\d+)') + + + def get_timeslot(self, s): + """Get start and end time for a timeslot. + """ + + timeslot = self.timeslot_re.search(s) + + start = timeslot.group(1) + end = timeslot.group(2) + + return start, end + + + def get_month_day(self, s): + """Get month and day. + """ + + month_day = self.month_day_re.search(s) + + month = month_day.group(1) + day = month_day.group(2) + + return month, day + + class LPSRenderer(Renderer): """Helps in converting Markdown version of LP schedule to a dictionary. """ |