Skip to content

Instantly share code, notes, and snippets.

@abeyer
Created November 17, 2015 04:06
Show Gist options
  • Save abeyer/7da6379bde3277d35258 to your computer and use it in GitHub Desktop.
Save abeyer/7da6379bde3277d35258 to your computer and use it in GitHub Desktop.
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