Skip to content

Instantly share code, notes, and snippets.

@yunruse
Created January 14, 2022 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunruse/fb18036b5c5b05346ec7bbd874a259e3 to your computer and use it in GitHub Desktop.
Save yunruse/fb18036b5c5b05346ec7bbd874a259e3 to your computer and use it in GitHub Desktop.
University of Edinburgh event pre-booking calendar generator

Pre-booking calendar generator

If you have a pre-booking site which has a series of lectures, where you can pre-book a slot 24 hours early for not open and 48 hours early for *not open, this generator will turn all that headache into a calendar that will tell you when to book, that you can import into your calendar app.

How to use

  • Download ed_event.py to a folder.
  • Go to the booking website. Put the URL in the first line of a text file, and hit enter.
  • Then, go to the website, hit ctrl-a / cmd-a to grab the whole site in plain text, and paste it.
  • Save this as event.txt in the same folder as ed_event.py.

The text file should look similar to:

https://ease.homepages.inf.ed.ac.uk/cgi/jcb/cosign/events.pl?event=fnlp
You are Mia Dobson (s1803409).

Foundations of Natural Language Processing
  • Assuming you have Python installed, go to the command line and run:

    pip install ics python ed_event.py

  • You will see an "event-prebook.ics" file. Import it into whatever calendar you're using. (If you're using your OS built-in calendar app you should be able to just double-click the file to import it.)

from datetime import datetime, timedelta
import re
from ics import Calendar, Event
def read(path):
calendar = Calendar()
with open(path) as f:
description = None
for line in f.readlines():
line = line.strip()
if line.startswith('https://'):
description = line
if not '2022' in line:
continue
chunks = line.split('\t')
l_name = chunks[0]
l_early = '*' in line
ds = ' '.join(map(str.strip, chunks[3:7]))
l_start = datetime.strptime(ds, '%d %b %Y, %H:%M')
if l_early:
l_book = l_start - timedelta(days=2)
else:
l_book = l_start - timedelta(days=1)
calendar.events.add(Event(
name="{}: booking starts".format(l_name),
begin=l_book,
end=l_book + timedelta(minutes=10),
description=description
))
with open('event-prebook.ics', 'w') as f:
print(calendar, file=f)
if __name__ == '__main__':
c = read('event.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment