Vobject implementation
[frenchie/icalparse.git] / parserrules.py
index 61a09e5..cf0fbd6 100644 (file)
@@ -1,18 +1,71 @@
 #!/usr/bin/python
 
-# This file describes a series of rules which will be called on an ics file as
-# rule(key, value)
-
-# Your functions are expected to return a (key, value) tuple or they will be treated as
-# if they don't exist (ie, the line will go through unhindered). Returning a value which
-# is boolean False will remove the offending line from the final  ICS. The easiest way
-# to pass a line back without changing it is to return True.
-
-# The doc string will be presented to the user when run as verbose, so please be polite
-
-def markEventsPublic(key, value):
-       '''Marking private events public'''
-       # Required as google are strict about the CLASS:PRIVATE/CLASS:CONFIDENTIAL lines
-       if key == 'CLASS':
-               return (key, 'PUBLIC')
-       return True
+# Rules for tackling facebook and google calendar - I want visibility of the
+# organiser... not useful Google!
+
+import vobject
+
+def facebookOrganiser(cal):
+       '''Adds organiser details to the body of facebook calendars.'''
+
+       if cal.contents.has_key(u'prodid'):
+               if not "Facebook" in cal.prodid.value: return cal
+
+       for event in cal.vevent_list:
+               if not event.contents.has_key(u'organizer'): continue
+               organizer = "Organised by: " + event.organizer.cn_param + " ("
+               organizer += event.organizer.value.lstrip('MAILTO:') + ")\n\n"
+
+               event.description.value = organizer + event.description.value
+
+       return cal
+
+def whatPrivacy(cal):
+       '''Marks events public so google calendar doesn't have a sad about them.'''
+
+       for event in cal.vevent_list:
+               if event.contents.has_key(u'class'):
+                       del event.contents[u'class']
+                       # Bit of a hack as class is a reserved word in python
+                       event.add('class').value = "PUBLIC"
+
+       return cal
+
+def dropMSKeys(cal):
+       '''Drops microsoft keys, good for outlook, just bandwidth when not.'''
+
+       eventBlacklist = [x.lower() for x in [
+               "X-ALT-DESC",
+               "X-MICROSOFT-CDO-BUSYSTATUS",
+               "X-MICROSOFT-CDO-IMPORTANCE",
+               "X-MICROSOFT-DISALLOW-COUNTER",
+               "X-MS-OLK-ALLOWEXTERNCHECK",
+               "X-MS-OLK-AUTOSTARTCHECK",
+               "X-MS-OLK-CONFTYPE",
+               "X-MS-OLK-AUTOFILLLOCATION"
+       ]]
+
+       vcalBlacklist = [x.lower() for x in [
+       "X-CALEND",
+       "X-CALSTART",
+       "X-CLIPEND",
+       "X-CLIPSTART",
+       "X-MS-OLK-WKHRDAYS",
+       "X-MS-OLK-WKHREND",
+       "X-MS-OLK-WKHRSTART",
+       "X-OWNER",
+       "X-PRIMARY-CALENDAR",
+       "X-PUBLISHED-TTL",
+       "X-WR-CALDESC",
+       "X-WR-CALNAME",
+       "X-WR-RELCALID"
+       ]]
+
+       for event in cal.vevent_list:
+               for blacklist in eventBlacklist:
+                       if event.contents.has_key(blacklist): del event.contents[blacklist]
+
+       for blacklist in vcalBlacklist:
+               if cal.contents.has_key(blacklist): del cal.contents[blacklist]
+
+       return cal

UCC git Repository :: git.ucc.asn.au