X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=parserrules.py;h=4ba71e8a3544d20e9a5502c22d6d059f9bb2a96a;hb=a60d888467b796bdf7ed7cd63c53cef8dcfc779c;hp=cf60f984f6695d3ef398b7b4154bd37306c786e0;hpb=5dc6aee6a1edf911312f0d7fea022dd44410bd42;p=frenchie%2Ficalparse.git diff --git a/parserrules.py b/parserrules.py index cf60f98..4ba71e8 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.''' @@ -59,6 +62,8 @@ def whatPrivacy(cal): def dropAttributes(cal): '''Removing unwanted metadata''' + if "facebook" in ruleConfig: + if ruleConfig["facebook"] == True: return cal eventBlacklist = [x.lower() for x in [ "X-ALT-DESC", @@ -100,12 +105,13 @@ def dropAttributes(cal): def exDate(cal): '''Replacing multi-value EXDATES with multiple single-value EXDATES''' + if "facebook" in ruleConfig: + if ruleConfig["facebook"] == True: return cal 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 +129,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 +168,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