Created
November 17, 2015 04:06
-
-
Save abeyer/7da6379bde3277d35258 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import icalendar | |
import pytz | |
strkeys = ['UID','SUMMARY','LOCATION','DESCRIPTION'] | |
timekeys = ['DTSTART', 'DTEND'] | |
otherkeys = ['STATUS'] | |
tz = pytz.timezone("US/Pacific") | |
regex = re.compile(r'^\(.*\)') | |
def mkdict(e): | |
d=dict() | |
for k in strkeys: | |
d[k] = unicode(e[k]) | |
for k in timekeys: | |
d[k] = e[k].dt.astimezone(tz).strftime(u'%Y-%m-%d %H:%M') | |
d['STATUS'] = regex.search(d['SUMMARY']).group() | |
d['SUMMARY'] = u' '.join(d['SUMMARY'].split()[1:]) | |
return d | |
def read_cal(fn): | |
with open(fn, 'r') as f: | |
return icalendar.Calendar.from_ical(f.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment