开发者

Backup Google Calendar programmatically: https://www.google.com/calendar/exporticalzip

I'm struggling with writing a python script that automatically grabs the zip fail containing all my google calendars and stores it (as a backup) on my harddisk.

I'm using ClientLogin to get an authentication token (and successfully can obtain the token).

Unfortunately, i'm unable to retrieve the file at https://www.google.com/calendar/exporticalzip

It always asks me for the login credentials again by returning a login page as html (instead of the zip).

Here's the critical code:

post_dat开发者_Python百科a = post_data = urllib.urlencode({ 'auth': token, 'continue': zip_url})
request = urllib2.Request('https://www.google.com/calendar', post_data, header)
try:
  f = urllib2.urlopen(request)
  result = f.read()
except:
  print "Error"

Anyone any ideas or done that before? Or an alternative idea how to backup all my calendars (automatically!)


You could write a script with mechanize to walk through google login process before downloading Calendar from your preferred url.

So try with:

import mechanize
br=mechanize.Browser()
br.open('https://www.google.com/calendar/exporticalzip')
br.select_form(nr=0)
br['Email']='Username@gmail.com'
br['Passwd']='Password'
br.submit()
br.retrieve('https://www.google.com/calendar/exporticalzip','exportical.zip')

It worked for me, i downloaded my zipped ical calendar succesfully.


Calendars have an URL which allows you to download it without authentication (see Google Calendar's UI, Calendar settings, under Private URL). You should be able to download the iCal or XML file using urllib without problems.


Great solution systempuntoout! For those of you using Google Apps, just needs a tweak to the URLs and the Email.

import mechanize
br=mechanize.Browser()
br.open('https://www.google.com/calendar/hosted/yourdomain.com/exporticalzip')
br.select_form(nr=0)
br['Email']='Username'
br['Passwd']='Password'
br.submit()
br.retrieve('https://www.google.com/calendar/hosted/yourdomain.com/exporticalzip','exportical.zip')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜