Skip to content

Instantly share code, notes, and snippets.

@dstanek
Last active October 20, 2016 21:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dstanek/83d536af9461eb26d7a19ff73a7391c2 to your computer and use it in GitHub Desktop.
Save dstanek/83d536af9461eb26d7a19ff73a7391c2 to your computer and use it in GitHub Desktop.
Create a personalized iCal for the OpenStack Newton Summit schedule
#!/usr/bin/env python3
# Download https://www.openstack.org/summit/austin-2016/summit-schedule/mine/?goback=1
# to mine.html and then run this script. The my.ics can be imported into your
# calendar.
#
# Common problems:
# - i've only tested against my calendar (and got feedback about bugs from others) so
# so you may find the parsing isn't quite right
import datetime
import json
import re
import ics
def fix_json(data):
# yes, this is terribad
for line in data.split('\n'):
line = line.replace('\\', '') # i just don't care
match = re.search(r'\s*([\w_]+): (.*)', line)
if match:
yield '"{}": {}'.format(*match.groups())
else:
yield line
def get_dt(day, time):
date_template = '2016-04-{:02d} '.format(int(day))
date = date_template + time + ' -0500'
return datetime.datetime.strptime(date, '%Y-%m-%d %I:%M%p %z')
calendar = ics.Calendar()
html = open('mine.html', encoding='utf-8').read()
r = r'events\["[^\]0-9]*([0-9]*)"].push\(([^}]+})'
for match in re.finditer(r, html, re.MULTILINE|re.DOTALL):
day, data = match.groups()
data = json.loads(''.join(fix_json(data)))
date_template = '2016-04-{:02d} '.format(int(day))
begin = get_dt(day, data['start_time'])
end = get_dt(day, data['end_time'])
url = ('https://www.openstack.org/summit/austin-2016/'
'summit-schedule/events/{:d}').format(data['id'])
location = data['room']
event = ics.Event(name=data['title'], begin=begin, end=end, #url=url,
location=location, description='Details: {}'.format(url))
event.uid = 'dstanek-{}-event'.format(data['id'])
calendar.events.append(event)
with open('my.ics', 'w', encoding='utf-8') as f:
f.writelines(calendar)
@dhellmann
Copy link

I had to change this to r = r'events["[^]0-9]([0-9])"].push(([^}]+})' to deal with titles that include parens.

@dstanek
Copy link
Author

dstanek commented Apr 20, 2016

Thanks Doug! The gist has been updated.

@tmmorin
Copy link

tmmorin commented Oct 20, 2016

Does anyone have something like this for Barcelona ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment