Skip to content

Instantly share code, notes, and snippets.

@bldewolf
Created August 21, 2012 06:37
Show Gist options
  • Save bldewolf/3412714 to your computer and use it in GitHub Desktop.
Save bldewolf/3412714 to your computer and use it in GitHub Desktop.
Pull down a calendar file and merge it into a local one
#!/usr/bin/python
import vobject
import sys
import os
from urllib import urlopen
# Hack for RFC violations
vobject.icalendar.escapableCharList = '\\;,Nn"\'&'
url = "THE ICS CALENDAR THAT WILL BE UPDATED THAT YOU WANT TO MERGE FROM"
calendar = "YOUR LOCAL ICS FILE THAT YOU WANT EVERYTHING COMBINED INTO"
fnew = urlopen(url).read()
fcal = open(calendar)
newcal = vobject.readOne(fnew)
calcal = vobject.readOne(fcal)
fcal.close()
for ev in newcal.vevent_list:
for derp in calcal.vevent_list:
if ev.contents["uid"] == derp.contents["uid"]:
calcal.vevent_list.remove(derp)
calcal.add(ev)
fout = open(calendar+".tmp","w")
fout.write(calcal.serialize())
fout.close()
os.rename(calendar+".tmp", calendar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment