From 6100aaa206649267c2864bd9d661f06b7bdd67b5 Mon Sep 17 00:00:00 2001 From: Julien Valroff Date: Tue, 3 Jan 2012 18:35:22 +0100 Subject: [PATCH] Autocommit of file /home/julien/scripts/gglcal-notify changed on host ares --- gglcal-notify | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 gglcal-notify diff --git a/gglcal-notify b/gglcal-notify new file mode 100644 index 0000000..0f3725e --- /dev/null +++ b/gglcal-notify @@ -0,0 +1,56 @@ +#!/usr/bin/pyhton +# Ptyhon script to send a notification when an event with an alert occurs +# Source: http://julien.danjou.info/blog/2012/google-calendar-pynotify +# By Julien Danjou + +# First, we need to import GTK+ and pynotify, and initialize it. +import gtk +import pynotify +pynotify.init(sys.argv[0]) + +# Then, we need to import gdata Calendar API and connect to the calendar. I'll +# use the simple email/password way to login, which is clearly not the best, but +# it's also the simplest. Feel free to use OAuth 2.0. :-) +calendar_service = gdata.calendar.service.CalendarService() +calendar_service.email = 'mygooglelogin' +calendar_service.password = 'mygooglepassword' +calendar_service.ProgrammaticLogin() + +# Now we're ready to request stuff and notify! First, request the events from +# the default calendar. +feed = calendar_service.GetCalendarEventFeed() + +# Now we can iterate over feed and do various checks. +for event in feed.entry: + # If the event status is not confirmed, go to the next event. + if event.event_status.value != "CONFIRMED": + continue + # Now iterate over all the event dates (usually it has one) + for when in event.when: + # Parse start and end time + try: + start_time = datetime.datetime.strptime(when.start_time.split(".")[0], "%Y-%m-%dT%H:%M:%S") + end_time = datetime.datetime.strptime(when.end_time.split(".")[0], "%Y-%m-%dT%H:%M:%S") + except ValueError: + # ValueError happens on parsing error. Parsing errors + # usually happen for "all day" events since they have + # not time, but we do not care about this events. + continue + now = datetime.datetime.now() + # Check that the event hasn't already ended + if end_time > now: + # Check each alert + for reminder in when.reminder: + # We handle only reminders with method "alert" + # and whose start time minus the reminder delay has passed + if reminder.method == "alert" \ + and start_time - datetime.timedelta(0, 60 * int(reminder.minutes)) < now: + # Build the notification + notification = pynotify.Notification(summary=event.title.text, + message=event.content.text) + # Set an icon from the GTK+ stock icons + notification.set_icon_from_pixbuf(gtk.Label().render_icon(gtk.STOCK_DIALOG_INFO, + gtk.ICON_SIZE_LARGE_TOOLBAR)) + notification.set_timeout(0) + # Show the notification + notification.show() -- 2.20.1