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

I am afraid to write a python script that automatically captures the zip failure containing all my google calendars and saves it (as a backup) on my hard drive.

I use ClientLogin to get the authentication token (and I can successfully get the token).

Sorry, I can’t get the file at https://www.google.com/calendar/exporticalzip

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

Here's the critical code:

post_data = 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" 

Any ideas or have done this before? Or an alternative idea how to backup all my calendars (automatically!)

+4
source share
3 answers

You can write a script with mechanize to go through the Google login process before downloading the 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') 

This worked for me, I successfully uploaded my zip calendar.

+5
source

Calendars have a URL that allows you to download it without authentication (see "Google Calendar UI", "Calendar Settings" under a personal URL). You should be able to upload an iCal or XML file using urllib without any problems.

0
source

Great systempuntoout solution! For those of you using Google Apps, you just need to set up URLs and 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
source

Source: https://habr.com/ru/post/1305222/


All Articles