summaryrefslogtreecommitdiffstats
path: root/lps_gen.py
diff options
context:
space:
mode:
authorrsiddharth <rsd@gnu.org>2016-03-15 23:31:16 -0400
committerrsiddharth <rsd@gnu.org>2016-03-15 23:31:16 -0400
commit7f6af7acf2bdeb216ed6db847d98eeaf13326010 (patch)
treea1c4b3f0d96c2c57fde4ce27f16764f9105e18ab /lps_gen.py
parentd17f9e74e4d409fb9f07cfd38c956d6b9af7f43c (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.py39
1 files changed, 39 insertions, 0 deletions
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 @@
# <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.
"""