Skip to content

Instantly share code, notes, and snippets.

@Wemmy0
Created September 21, 2024 14:01
Show Gist options
  • Save Wemmy0/660111abb0b82e8fd359ef9641d60466 to your computer and use it in GitHub Desktop.
Save Wemmy0/660111abb0b82e8fd359ef9641d60466 to your computer and use it in GitHub Desktop.
# Take an ICS file and split events into lectures and practicals based on their name
# Made for Newcastle University timetables downloaded from https://timetables.ncl.ac.uk/
from ics import Calendar
with open('timetable.ics', 'r') as file:
ics_content = file.read()
events = list(Calendar(ics_content).events)
lecture = Calendar()
practical = Calendar()
for event in events:
if 'P' in event.name:
practical.events.add(event)
else:
lecture.events.add(event)
with open('lecture.ics', 'w') as file:
file.writelines(lecture.serialize_iter())
with open('practical.ics', 'w') as file:
file.writelines(practical.serialize_iter())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment