Created
August 21, 2012 06:37
-
-
Save bldewolf/3412714 to your computer and use it in GitHub Desktop.
Pull down a calendar file and merge it into a local one
This file contains 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/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