Hi, I am having an issue creating an event that displays in the
correct time zone in google calendar. Here are the steps that I'm
using:

1. In your google calendar, set the default calendar time zone to
'US/Eastern'. You can set the default time zone by clicking the
"Settings" link underneath the list of calendars, and then clicking
the "General" tab.

2. Create another calendar, called "Pacific", and set the time zone to
'US/Pacific'.

3. Using the google api in python, I then add an event to the Pacific
calendar and I send the start time and end time in UTC, with a "Z" at
the end of the string.

4. When I login to the calendar, the event that I added to the Pacific
calendar is displayed with a time corresponding to the Eastern time
zone.

The code that I use to accomplish step 3 is listed below. Also, if
anyone knows an easier way to obtain the correct calendar feed
(currently I do it by string parsing) that would be appreciated.
Cheers.

Tim

------------------------------------
import sys

import atom
import gdata.contacts
import gdata.contacts.service
import gdata.calendar
import gdata.calendar.service


def main():
        
        # edit these fields
        email = '[email protected]'
        password = 'password'
        calendarName = 'pacific'
        start_time = '2009-07-14T12:00:00.000Z'
        end_time = '2009-07-14T15:00:00.000Z'
        
        # get credentials
        gd_calendar = gdata.calendar.service.CalendarService()
        gd_calendar.email =  email
        gd_calendar.password = password
        gd_calendar.source = 'test-timezone-Adapter'
        gd_calendar.ProgrammaticLogin()
        
        # get the primary calendar
        feed = gd_calendar.GetOwnCalendarsFeed()

        # find the specific calendar
        calendarFeed = None
        for entry in feed.entry:
                if entry.title.text == calendarName:
                        calendarFeed = entry
                        break
        if not calendarFeed:
                print "Error finding calendar '{0}'".format(calendarName)
                return 1
        
        # there is probably an easier way to find the calendar id, but I don't 
know it!
        lnk =  calendarFeed.id.text
        start = lnk.rfind('/') + 1
        end = lnk.find('%40group.calendar.google.com')
        calendarFeed =
"/calendar/feeds/{[email protected]/private/full".format(lnk[start:end])
        
        # create a new event
        googleEvent = gdata.calendar.CalendarEventEntry()
        googleEvent.title = atom.Title(text='the subject')
        googleEvent.content = atom.Content(text='a description')
        googleEvent.where.append(gdata.calendar.Where(value_string='a 
location'))
        googleEvent.when.append(gdata.calendar.When(start_time=start_time,
end_time=end_time))
        
        new_event = gd_calendar.InsertEvent(googleEvent, calendarFeed)
        if not new_event:
                print "Error creating event."
                return 1
                
        print "Created event at start time '{0}' in calendar '{1}'".format( \
                        start_time, calendarName)

        return 0

if __name__ == '__main__':
        sys.exit(main())

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to