Adding Events to Secondary Google Calendars in Python
Posted on
September 28th, 2008 by
Ray Baxter
Before writing, I assumed that I would need to refer any reader to the introductory post of this series on adding events to secondary calendars. Depending on your skill level and experience that may still be true, and it definitely is true if you want to understand what you are doing, but if you just want to get it done, you can probably muddle through with the following instructions.
Here’s the really short story: when you call the insertEvent method, you pass the event that you are creating and optionally, the edit url of the calendar where you want the event to appear. So, to create an event on a secondary calendar, just pass the edit link of the calendar. (You can get the edit link of a calendar in python by calling GetEditLink().href on it.)
For the longer story, I’ll assume that you have installed Python, ElementTree and the Google Data Python Library, following Google’s instructions.
Run through the tests and the sample code. When I ran the calendarExample.py it failed with this stack trace:
Traceback (most recent call last): File "./samples/calendar/calendarExample.py", line 577, in <module> main() File "./samples/calendar/calendarExample.py", line 574, in main sample.Run(delete) File "./samples/calendar/calendarExample.py", line 498, in Run self._PrintAllEventsOnDefaultCalendar() File "./samples/calendar/calendarExample.py", line 99, in _PrintAllEventsOnDefaultCalendar print '\t\t\t%s' % (a_participant.attendee_status.value,) AttributeError: 'NoneType' object has no attribute 'value'
Since all I wanted to do was to make this sample code run for the single case of adding an event to a secondary calendar, I commented out line 99, but the code should be checking that there is an attendee status before writing its value. After that change the sample code ran fine for me.
To insert a single event in a secondary calendar, I copied calendarExample.py to secondaryCalendarInsert.py. Then I commented out everything in the Run method except this line:
503 | see = self._InsertSingleEvent() |
and made the following change,
266 267 | new_event = self.cal_client.InsertEvent(event, '/calendar/feeds/g5b79g3f2bi5hc1it41seuu41c@group.calendar.google.com/private/full') |
This instructs the InsertEvent method to create the event in my secondary calendar by POSTing to the url of my “Secondary Calendar” (id g5b79g3f2bi5hc1it41seuu41c@group.calendar.google.com) instead of my primary calendar (id default). I found the calendar ID on the calendar settings page of the calendar, but as I said above, if you have accessed a calendar programatically, you can just call GetEditLink().href on it to get the proper link.
You can see that a “One Time Tennis with Beth” event was inserted beginning at the moment I did the insert and lasting for one hour, as described in the sample code.
[Update 2008-11-14: You can't see this if you are using Safari. In general embedded calendar's show in Safari, but there is something about this particular calendar that causes it not to display. Google does a number of separate calls and redirects to obtain the correct data for this calendar and it looks like one of the calls returns data that doesn't correspond to the mime-types. The point that I was trying to communicate with this illustration was that the event did in fact appear and that it was on the secondary calendar.]
2 Responses to “Adding Events to Secondary Google Calendars in Python”
Leave a Reply
Search:
Recent Posts
- Embedding Private and Shared Calendars – Google Apps for Your Domain
- Embedding Private and Shared Google Calendars
- Restyle Google Calendar
- Single Purpose Web Dev Browser
- The iCalendar validation project « Jon Udell
Categories
Relevant Links
AtomPub
- Getting to know the Atom Publishing Protocol, Part 1: Create and edit Web resources with the Atom Publishing Protocol
- Getting to know the Atom Publishing Protocol, Part 2: Put the Atom Publishing Protocol (APP) to work
Date and Time
GCalendar
- Articles and Tutorials
- Bugs and Enhancements
- Calendar API FAQ
- Calendar Feeds
- CalVis
- Developer’s Guide
- Google Calendar Data API Group
- Reference Guide
GData
- Authentication
- Batch Processing
- CalVis
- Client Libraries
- Common Elements
- Issues
- libgcal
- Overview
- Protocol Basics
- Protocol Reference
- Reference
- Samples
- Zend Documentation
iCalendar Tools
Online Calendars
- 30 Boxes
- CalendarHub – Web Calendars
- Google Calendar
- LuckyCal.com
- Online calendar publishing: Google Calendar
- Online calendar publishing: iCal
- Online calendar publishing: Outlook
- RSSCalendar
- The Human Calendar
- Yahoo! Calendar

September 28th, 2008 at 2:37 pm
[...] Python – Complete September 29, 2008 Php .NET Java Javascript Objective C Ruby [...]
October 28th, 2009 at 7:01 am
Getting an error when I follow your directions.
Traceback (most recent call last):
File “./secondaryCalendarExample.py”, line 600, in
main()
File “./secondaryCalendarExample.py”, line 597, in main
sample.Mark()
File “./secondaryCalendarExample.py”, line 506, in Mark
self.cal_client.InsertEvent(event, fitnessEditUrl)
File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/gdata/calendar/service.py”, line 159, in InsertEvent
converter=gdata.calendar.CalendarEventEntryFromString)
File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/gdata/service.py”, line 1183, in Post
media_source=media_source, converter=converter)
File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/gdata/service.py”, line 1292, in PostOrPut
redirects_remaining – 1, media_source, converter=converter)
File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/gdata/service.py”, line 1303, in PostOrPut
‘reason’: server_response.reason, ‘body’: result_body}
gdata.service.RequestError: {’status’: 400, ‘body’: ‘[Line 2, Column 93, element ns0:content] Malformed MIME type’, ‘reason’: ‘Bad Request’}