Archive for March 22, 2009

Automatically populating a gcal event with reminders

I find it irritating to have to set reminders for google events by hand, so in the theme of efficient-over-effective here is a the of a django project which will create a new event in google calendar with several reminders and redirect you to a page for editing its details. If you have a virtual server you could host this project there. You can then bookmark this url on the machines you use.

A little (if any) adaptation would make this work on google app engine (and might even allow you to login without hard coding a password).

Alternatives would be to write a greasemonkey script for google reader or write a ubiquity command that does this and redirects you to the page – but both these things seem more difficult to debug.

from django.conf.urls.defaults import patterns
from django.http import HttpResponseRedirect

import atom
import datetime
from gdata.calendar import CalendarEventEntry, When, Reminder
from gdata.calendar.service import CalendarService

def create_reminder(req):
    S = CalendarService() = "EMAIL@ADDRESS"
    S.password = "password1"

    event = CalendarEventEntry()
  1. starttime is manditory - tomorrow seems as good a day as any
def make_google_dt(dt): return dt.strftime('%Y-%m-%dT%H:%M:%S.000Z') now = start_datetime = now + datetime.timedelta(days=1) start_time = make_google_dt(start_datetime) end_time = make_google_dt(start_datetime + datetime.timedelta(minutes=30)) occurence = When(start_time=start_time, end_time=end_time) occurence.reminder = [ Reminder(hours=3, extension_attributes={'method':'sms'}), Reminder(days=2, extension_attributes={'method':'email'}),
  1. to feel happily surprised but not panic
Reminder(days=7, extension_attributes={'method':'email'}), Reminder(days=14, extension_attributes={'method':'email'}), ] event.when.append(occurence) new_event = S.InsertEvent(event, '/calendar/feeds/default/private/full') edit_link = new_event.GetHtmlLink().href return HttpResponseRedirect(edit_link) urlpatterns = patterns('', (r'', create_reminder) )

Note that this is a slighlty evil – insofar as a GET request is having side effects… but POST commands are slightly troublesome to book mark, and adding a layer of indirection slightly defeats the purpose.

Technical notes

  • Underneath the python library this is constructing and xml command and sending this to a google webservice.
  • The python library does really support email reminders. It does however support adding arbitrary attributes to the xml element representing the reminder:

    Reminder(days=7, extension_attributes={'method':'email'})

    this add method=”email” to the reminder tag. (One can also set method=sms).

    This is not documented in the google python documentation. It is (I think) documented in the gdata plain xml documentation.

  • For a working reference implementation in javascript using plain xml see the gtd tickler greasemonkey gmail plugin.

Useful references

March 22, 2009 at 8:56 pm Leave a comment

Getting python argspecs

For the benefit of google:

def f(x, *args, **kwargs):
    return x
import inspect
print inspect.getargspec(f)

March 22, 2009 at 7:57 pm Leave a comment

March 2009
« Feb   Apr »