Merge lp:~timfreund/python-snippets/calendar-snippets into lp:~jonobacon/python-snippets/trunk

Proposed by Tim Freund
Status: Needs review
Proposed branch: lp:~timfreund/python-snippets/calendar-snippets
Merge into: lp:~jonobacon/python-snippets/trunk
Diff against target: 101 lines (+80/-0)
3 files modified
CATEGORIES (+1/-0)
calendar/createevent.py (+47/-0)
calendar/readical.py (+32/-0)
To merge this branch: bzr merge lp:~timfreund/python-snippets/calendar-snippets
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+25854@code.launchpad.net

Description of the change

Two snippets: one reads an iCal calendar from the network and iterates through the events, and the other takes an iCal VEVENT and adds it to the user's Evolution calendar.

To post a comment you must log in.

Unmerged revisions

101. By Tim Freund

Create an event in the local user's Evolution calendar

100. By Tim Freund

Read an iCal calendar and iterate through the events.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CATEGORIES'
--- CATEGORIES 2010-04-24 18:34:32 +0000
+++ CATEGORIES 2010-05-23 19:45:36 +0000
@@ -15,6 +15,7 @@
15 Application Indicator Application indicator examples.15 Application Indicator Application indicator examples.
16 bzrlib Bazaar source control system Python module.16 bzrlib Bazaar source control system Python module.
17 Cairo Cairo drawing examples17 Cairo Cairo drawing examples
18 calendar Calendar examples
18 Clutter Clutter toolkit examples.19 Clutter Clutter toolkit examples.
19 csv csv Python module, reading and writing CSV files20 csv csv Python module, reading and writing CSV files
20 dbus dbus messaging system21 dbus dbus messaging system
2122
=== added directory 'calendar'
=== added file 'calendar/createevent.py'
--- calendar/createevent.py 1970-01-01 00:00:00 +0000
+++ calendar/createevent.py 2010-05-23 19:45:36 +0000
@@ -0,0 +1,47 @@
1#!/usr/bin/env python
2#
3# [SNIPPET_NAME: Create a Calendar Event]
4# [SNIPPET_CATEGORIES: calendar]
5# [SNIPPET_DESCRIPTION: Create a Calendar Event in your local Evolution calendar]
6# [SNIPPET_AUTHOR: Tim Freund <tim@freunds.net>]
7# [SNIPPET_LICENSE: MIT]
8
9
10
11try:
12 from evolution import ecal
13except ImportError:
14 print """The python-evolution package is not installed.
15On Ubuntu? Run the following: 'sudo apt-get install python-evolution'"""
16
17# Find the user's 'Personal' calendar
18for cal_meta in ecal.list_calendars():
19 # cal_meta[0] is the calendar name
20 # cal_meta[1] is the calendar url
21 if cal_meta[0] == 'Personal':
22 print "Opening %s" % cal_meta[1]
23 calendar = ecal.open_calendar_source(cal_meta[1], ecal.CAL_SOURCE_TYPE_EVENT)
24
25# Get an ical VEVENT string. See the 'Read an iCal calendar' snippet
26# for an example of downloading an iCal calendar from the network.
27ical_string = """BEGIN:VEVENT
28UID:fq2vt055fu3rjv24t32mv8fv80@google.com
29DTSTART:20100521T140000Z
30DTEND:20100521T150000Z
31CLASS:PUBLIC
32CREATED:20100523T185147Z
33DESCRIPTION:Discussing the status of the Acire calendar snippets.
34DTSTAMP:20100523T190209Z
35LAST-MODIFIED:20100523T185636Z
36LOCATION:14 West 10 Street\, Kansas City\, MO 64105
37SEQUENCE:4
38STATUS:CONFIRMED
39SUMMARY:Status Meeting
40TRANSP:OPAQUE
41END:VEVENT
42"""
43
44event = ecal.ECalComponent(ecal.CAL_COMPONENT_EVENT, ical_string)
45# events added will show up immediately in the Evolution UI
46calendar.add_object(event)
47
048
=== added file 'calendar/readical.py'
--- calendar/readical.py 1970-01-01 00:00:00 +0000
+++ calendar/readical.py 2010-05-23 19:45:36 +0000
@@ -0,0 +1,32 @@
1#!/usr/bin/env python
2#
3# [SNIPPET_NAME: Read an iCal calendar]
4# [SNIPPET_CATEGORIES: calendar]
5# [SNIPPET_DESCRIPTION: Read an iCal calendar with python-vobject]
6# [SNIPPET_AUTHOR: Tim Freund <tim@freunds.net>]
7# [SNIPPET_LICENSE: MIT]
8
9try:
10 import vobject
11except ImportError:
12 print """The vobject package is not installed.
13On Ubuntu? Run the following: 'sudo apt-get install python-vobject'
14Other users can find the package here: http://vobject.skyhouseconsulting.com/"""
15
16# First we need the ical document. We will use urllib2 to download
17# one from the net.
18from urllib2 import urlopen
19ical_string = urlopen('http://tim.freunds.net/media/files/python-snippets/acire.ical').read()
20
21# create a vcalendar object from the ical string:
22calendar = vobject.readOne(ical_string)
23
24# print event details for each event in the calendar
25for vevent in calendar.vevent_list:
26 print "Event: %s" % vevent.summary.value
27 print "\tLocated at: %s" % vevent.location.value
28 print "\tStart time: %s" % vevent.dtstart.value.strftime("%Y-%m-%d %H:%M")
29 print "\tEnd time: %s" % vevent.dtend.value.strftime("%Y-%m-%d %H:%M")
30
31 # ical vevent formatted strings can be retrieved by calling the serialize method:
32 # print vevent.serialize()

Subscribers

People subscribed via source and target branches