From: Fredrik Unger Date: Tue, 6 Nov 2012 14:46:36 +0000 (+0100) Subject: Renaming calendar to events due to naming collision in vobject. X-Git-Url: https://source.tree.se/git?p=treecutter.git;a=commitdiff_plain;h=1e847c4334487dd3f5c26202e17b00f1cf1c9d16 Renaming calendar to events due to naming collision in vobject. --- diff --git a/xinclude/calendar.py b/xinclude/calendar.py deleted file mode 100755 index a956ba0..0000000 --- a/xinclude/calendar.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/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") diff --git a/xinclude/events.py b/xinclude/events.py new file mode 100755 index 0000000..a956ba0 --- /dev/null +++ b/xinclude/events.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")