-
-
Save hhoover/4c617abffc9cf01eac57c33140b3a6e4 to your computer and use it in GitHub Desktop.
Create a personalized iCal for the OpenStack Newton Summit schedule
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
#!/usr/bin/env python3 | |
# Download https://www.openstack.org/summit/barcelona-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-10-{:02d} '.format(int(day)) | |
date = date_template + time + ' +0100' | |
return datetime.datetime.strptime(date, '%Y-%m-%d %I:%M%p %z') | |
calendar = ics.Calendar() | |
html = open('mine.htm').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-10-{:02d} '.format(int(day)) | |
begin = get_dt(day, data['start_time']) | |
end = get_dt(day, data['end_time']) | |
url = ('https://www.openstack.org/summit/barcelona-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') as f: | |
f.writelines(calendar) |
Author
hhoover
commented
Oct 21, 2016
•
Do you have an example of what your calendar looks like? The mine.html file it's reading.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment