X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=parserrules.py;h=a2175fed34e8168e62384de0275274f164be1b93;hb=ae40266069204ee411350d5fd3d31f40d89187af;hp=cf60f984f6695d3ef398b7b4154bd37306c786e0;hpb=4cd352c4a6906d90e171e36d3027e803009e4af6;p=frenchie%2Ficalparse.git diff --git a/parserrules.py b/parserrules.py index cf60f98..a2175fe 100644 --- a/parserrules.py +++ b/parserrules.py @@ -28,6 +28,9 @@ import vobject +ruleConfig = {} +ruleConfig["defaultTZ"] = "UTC" + def facebookOrganiser(cal): '''Adds organiser details to the body of facebook calendars.''' @@ -57,55 +60,13 @@ def whatPrivacy(cal): return cal -def dropAttributes(cal): - '''Removing unwanted metadata''' - - 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", - "TRANSP", - "SEQUENCE", - "PRIORITY" - ]] - - mainBlacklist = [x.lower() for x in [ - "X-CLIPSTART", - "X-CALSTART", - "X-OWNER", - "X-MS-OLK-WKHRSTART", - "X-MS-OLK-WKHREND", - "X-WR-RELCALID", - "X-MS-OLK-WKHRDAYS", - "X-MS-OLK-APPTSEQTIME", - "X-CLIPEND", - "X-CALEND", - "VTIMEZONE", - "X-PRIMARY-CALENDAR" - ]] - - for event in cal.vevent_list: - for blacklist in eventBlacklist: - if event.contents.has_key(blacklist): del event.contents[blacklist] - - for blkl in mainBlacklist: - while blkl in cal.contents: del cal.contents[blkl] - - return cal - def exDate(cal): '''Replacing multi-value EXDATES with multiple single-value EXDATES''' from datetime import datetime from pytz import timezone - default = timezone('Australia/Perth') - + default = timezone(ruleConfig["defaultTZ"]) for event in cal.vevent_list: if not event.contents.has_key(u'exdate'): continue @@ -123,12 +84,13 @@ def exDate(cal): return cal def utcise(cal): - '''Removing local timezones in favour of UTC''' + '''Removing local timezones in favour of UTC. If the remote calendar specifies a timezone + then use it, otherwise assume it's in the user-specified or default values''' from datetime import datetime from pytz import timezone - default = timezone('Australia/Perth') + default = timezone(ruleConfig["defaultTZ"]) for event in cal.vevent_list: dtstart = getattr(event, 'dtstart', None) @@ -161,21 +123,3 @@ def unwantedParams(cal): except AttributeError: continue return cal - -def exDate(cal): - '''Changes multi-EXDATE into singles (apple can't obey even simple specs)''' - - for event in cal.vevent_list: - if not event.contents.has_key(u'exdate'): continue - dates = event.exdate.value - try: tzid = event.exdate.tzid_param - except AttributeError: tzid = '' - - del event.contents[u'exdate'] - - for date in dates: - entry = event.add(u'exdate') - entry.value = [date] - if tzid: entry.tzid_param = tzid - - return cal