From 9b834e79e95c9ccc1f48aa38861b2864474aa9cc Mon Sep 17 00:00:00 2001 From: Fredrik Unger Date: Fri, 26 Oct 2012 09:05:13 +0200 Subject: [PATCH] Adding an initial calendar implementation. This calendar was developed in another git to begin with. It worked for displaying a calendar from apple calendar server. This will be a base for a rewrite. --- xinclude/calendar.py | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 xinclude/calendar.py diff --git a/xinclude/calendar.py b/xinclude/calendar.py new file mode 100755 index 0000000..a956ba0 --- /dev/null +++ b/xinclude/calendar.py @@ -0,0 +1,79 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import getpass +from dateutil.tz import *; from datetime import * +import vobject +import httplib +import urlparse +from lxml import etree +import sys +import re + +pw = getpass.getpass() +urlstr = "CALDAV ULR" +url = urlparse.urlparse(urlstr) +headers = {"User-Agent": "Mozilla/5.0", + "Content-Type": "text/xml", + "Accept": "text/xml"} + +headers['authorization'] = "Basic %s" % (("%s:%s" % (username, pw)).encode('base64')[:-1]) +handle = httplib.HTTPSConnection('tree.se','8443') +res = handle.request('GET', 'CALENDAR PATH', "", headers) +r = handle.getresponse() +if r.status != 200: + print "Failed to connect! Wrong Password ?" + sys.exit(5) +s = r.read() +events = [] +headers = ['dtstart','summary','location','description'] +for cal in vobject.readComponents(s): + for ev in cal.vevent_list: + details = {} + for k in headers: + details[k] = "" + for p in ev.getChildren(): + details[p.name.lower()] = p.value + events.append(details) +handle.close() + +sortedevents = sorted(events, key=lambda k: k['dtstart'], reverse=True) +output = u''' + +%s''' % (u'Stammtisch träffar') +for ev in sortedevents: + loc = ev['location'].split('[')[0] + if ev['location'].find('['): + lat = ev['location'].split('[')[1].split(',')[0] + lon = ev['location'].split('[')[1].split(',')[1].replace(']','') + loc = ' %s' % (lat,lon,loc) + output += u''' + +%s %s %s + + +%s + + + Tid + %s + + + Plats + %s + + + Beskrivning + %s + + + +''' % (ev['dtstart'].strftime('%Y'), + ev['dtstart'].strftime('%b'), + ev['dtstart'].strftime('%d'), + ev['summary'], + ev['dtstart'].strftime('%H:%M'), + loc, + ''.join(re.split('\n\n',unicode(ev['description'])))) +output += u'' +print output.encode("utf-8") -- 2.30.2