Similar to my previous post about backing up Gmail, this time I want to back up my here, from there it should be easy enough to derive the one for Google Calendar.

First, we have the same setup as last time. Yes, I’m still storing the passwords in plaintext. Perhaps I’ll write up a way to avoid this in the future.

#!/usr/bin/env python

import urllib, urllib2

password = '#####'

For the next step, I’m going to fetch Google’s login page using urllib. Note the service we’re sending in the POST parameters. This tells Google what we want to access (Google Reader in this case).

# Authenticate to obtain SID
auth_req_data = urllib.urlencode({
})
auth_req = urllib2.Request(auth_url, data=auth_req_data)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x)
auth_token = auth_resp_dict["Auth"]

Using the token returned from Google, we can download any files that need the permission we requested earlier. If you’d rather work with Google Calendar, the service that you need is 'cl'.

# Create a cookie in the header using the SID
print reader_resp_content
And that’s it. With those we’ll get an XML file that contains all of your current subscriptions. In my case, that’s being backed with all of the rest of my files. Again, it shouldn’t ever be necessary to have to use these, but better safe than sorry (particularly with 240 individual URLs). If you’d rather get your Google Calendars, you scan use the URL 'https://www.google.com/calendar/exporticalzip'.