msgbartop
by Brian Neal
msgbarbottom

15 Feb 09 Event Calendar – Use Google Calendar?

I wrote a pretty complex event calendar for my PHP-Nuke site. You can find it here on sourceforge. It allows users to submit events for admin approval. Once approved they appear on the calendar. The application does all the calendar logic, including the drawing of the calendar. Repeating events were added, and they are pretty hairy as well. There are some pretty massively complicated SQL queries in that code, not to mention some crazy PHP logic to figure out if repeating events belong on a particular calendar view. It is also possible to make exceptions to repeating events.

I’ve been thinking about how to port this to my new Django powered site. One day I stumbled across the Google Calendar API, and I’m thinking about leveraging this. I will let Google handle all the crazy calendar logic, as they are no doubt better at it than I am. I will still let users submit events to the admin, but this time I will use the Google API to add events to a Google Calendar. Google can do the heavy lifting for me when it comes to displaying events and handling repeating events. Am I cheating by doing this? Ha. Well there are some advantages to this idea for my end users:

  • Anyone can display the site calendar on their blog or website. It won’t just be available on my site.
  • Users can use the RSS feed that Google generates. It was always on the to-do list for the existing calendar to add this feature, but I never got around to it.
  • If a user has a Google account of their own, they can add events from the new calendar to their own calendars.
  • Google can configured to notify users by email or SMS text messages of events.

So I’ve decided to explore this approach. If it doesn’t look like it will pan out, I will fall back to a more direct port of my old PHP code.

This approach isn’t without its own challenges. I can see right now I am going to have to think carefully about how to provide authentication to the Django code to allow it to add events to one of my Google calendars. I obviously don’t want to hard code my Google login and password in the Django application.

I think I will attack this problem in phases:

  1. Get a calendar to display on my site. This should be pretty easy; just use Google’s iframe code.
  2. Add an event through the Python API to gain experience with it. This is prototype, throw-away code.
  3. Build a front-end interface to let users create events, as was done in the PHP application.
  4. Think about an interface for letting users change or edit events. This could range from just sending an email to the admin, who could make the changes using the Google interface on one end of the spectrum, all the way to letting Python code programatically making the changes.
  5. Add support for repeating events.

I’ve already downloaded the Python version of the gdata library and have started reading the API docs. It looks interesting. Once I get familiar with this library, it looks like I could use it for other cool things like interfacing with YouTube and Google Docs.

Tags: , , , ,

Reader's Comments

  1. |

    how did this API work out for you? i’m using modx and i need to have visitors submit events, which will need to be reviewed. and i’m stumped.

  2. |

    I’m just about ready to start using the gdata API. Right now I have a form built for a user to submit an event and hold it for approval. Next I need to build an admin function to approve events and use the gdata API to add them to a Google calendar. I should know more this weekend, time willing, and will report the results.

  3. |

    I am doing almost literally the same thing, any luck with this approach?

  4. |

    Yes. I haven’t gone live with this yet, but I have something working. The only thing I punted on for right now was repeating events. If you look at my later blog entries that are tagged with “calendar” you’ll see a few more posts on this matter.