From 7f6af7acf2bdeb216ed6db847d98eeaf13326010 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Tue, 15 Mar 2016 23:31:16 -0400 Subject: Add LPiCal class Contains two methods at the moment: - get_timeslot - get_month_day Addresses issue #8. --- lps_gen.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lps_gen.py') diff --git a/lps_gen.py b/lps_gen.py index aa50244..f6696b6 100644 --- a/lps_gen.py +++ b/lps_gen.py @@ -19,6 +19,7 @@ # . 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. """ -- cgit v1.2.3