Automatically populating a gcal event with reminders

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

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 urls.py 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()
    S.email = "EMAIL@ADDRESS"
    S.password = "password1"
    S.ProgrammaticLogin()

    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 = datetime.datetime.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

Entry filed under: Uncategorized.

Getting python argspecs Python generator to list decorator

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


March 2009
M T W T F S S
« Feb   Apr »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

%d bloggers like this: