Beginning of a series of changes to use vobject
authorJames French <[email protected]>
Mon, 13 Jun 2011 14:31:22 +0000 (22:31 +0800)
committerJames French <[email protected]>
Mon, 13 Jun 2011 14:31:22 +0000 (22:31 +0800)
It makes more sense to use a maintained library. What was an exercise in
unicode and ical RFCs is easier done by other people

icalparse.py
vobjectRules.py [new file with mode: 0644]

index d52ac7e..3cdc7f1 100755 (executable)
@@ -267,6 +267,21 @@ def writeOutput(cal, outfile=''):
                out.close()
 
 
+def vobjectRules(ics):
+       '''Applies rules to the ICS file before we have our way with it'''
+
+       try:
+               import vobjectRules
+       except ImportError:
+               sys.stderr.write('Vobject rules file could not be imported\n')
+               return ics
+
+       for rule in vobjectRules.runRules:
+               ics = rule(ics)
+
+       return ics
+
+
 if __name__ == '__main__':
        from optparse import OptionParser
        # If the user passed us a 'stdin' argument, we'll go with that,
@@ -282,6 +297,9 @@ if __name__ == '__main__':
        parser.add_option('-m','--encoding', dest='encoding', default='',
                help='Specify a different character encoding'
                '(ignored if the remote server also specifies one)')
+       parser.add_option('-r','--vobject-rules',
+               action='store_true', dest='vobject',
+               help='Run rules written for vobject stored in vobjectRules.py')
 
        (options, args) = parser.parse_args()
 
@@ -295,6 +313,7 @@ if __name__ == '__main__':
 
        (content, encoding) = getContent(url, options.stdin)
        encoding = encoding or options.encoding or 'utf-8'
+       if options.vobject: content = vobjectRules(content)
        cal = lineJoiner(content, encoding)
        ical = applyRules(splitFields(cal), generateRules(), options.verbose)
        output = lineFolder(joinFields(ical))
diff --git a/vobjectRules.py b/vobjectRules.py
new file mode 100644 (file)
index 0000000..33fb527
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+
+# Rules for tackling facebook and google calendar - I want visibility of the
+# organiser... not useful Google!
+
+import vobject
+import sys
+
+def facebookOrganiser(ics):
+       '''Adds organiser details to the body of facebook calendars.'''
+
+       cal = vobject.readOne(ics)
+
+       if cal.contents.has_key('PRODID'):
+               if not "Facebook" in cal.contents.prodid.value: return ics
+
+       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.serialize()
+
+runRules = [facebookOrganiser]

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