Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@darkcores
Created March 6, 2019 09:16
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 darkcores/26647ccdb33e59f63966ecccc4fd1ef6 to your computer and use it in GitHub Desktop.
Save darkcores/26647ccdb33e59f63966ecccc4fd1ef6 to your computer and use it in GitHub Desktop.
ical merge/filter
#!/usr/bin/env python3
import requests
from icalendar import Calendar
# Add entries using name: url
ICS = {
"": "",
}
# Strings to filter events / courses
FILTER = [
"",
]
class IcsToOrg:
def __init__(self):
self.data = dict()
def update_ics(self):
for k, v in ICS.items():
rdata = requests.get(v)
if rdata.status_code == 200:
self.data[k] = Calendar.from_ical(rdata.text)
else:
print("Error getting %s" % k)
def filter(self, val):
course = val.split(';')[0]
return len([True for x in FILTER if x in course]) > 0
def export_ics(self):
cal = Calendar()
cal.add('prodid', '-//Uhasselt Lessenroosters Merged//jorrit.info//')
cal.add('version', '2.0')
for k, v in self.data.items():
for c in v.walk():
summary = str(c.get('SUMMARY'))
if self.filter(summary):
cal.add_component(c)
fp = open("public_html/rooster.ics", "wb")
fp.write(cal.to_ical())
fp.close()
if __name__ == "__main__":
converter = IcsToOrg()
print("Getting new calendar file(s)")
converter.update_ics()
print("Exporting icals")
converter.export_ics()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment