Archive for December, 2009

dealing with “MySQL backend does not support timezone-aware datetimes”

When fetching events from an iCal feed and saving this into a database I got

MySQL backend does not support timezone-aware datetimes

This did the trick for me:

Install pytz (download here)

PYTHON:
  1. import pytz
  2. that_datetime_in_utc.astimezone(pytz.timezone('Europe/Zurich')).replace(tzinfo=None)

Caution: I don't really understand what I'm writing here - it feels like those posters in PHP forums who explain 'how to ...' and then trying to explain something they have no clue of, but well.. :-)

Fetch publicly available google calendar data with python

I tried accessing the google data api with python - that api seems either overly complicated or just not suited for just grabbing events from a public google calendar.

This worked for me:

  1. find out ical address (subscribe to the calendar, other calendars->arrow down->calendar settings)
  2. install icalendar

Then this is possible:

PYTHON:
  1. from icalendar import Calendar
  2. import urllib
  3. ics = urllib.urlopen('http://www.google.com/calendar/ical/fchppllvcaupb6fgguigobkfj4@group.calendar.google.com/public/basic.ics').read()
  4. ical=Calendar.from_string(ics)
  5. for vevent in ical.subcomponents:
  6.   if vevent.name != "VEVENT":
  7.     continue
  8.   title = str(vevent.get('SUMMARY'))
  9.   description = str(vevent.get('DESCRIPTION'))
  10.   location = str(vevent.get('LOCATION'))
  11.   start = vevent.get('DTSTART').dt             # a datetime
  12.   end = vevent.get('DTEND').dt                 # a datetime