Trying to get feeds from Google Calendar

brian_d_foy on 2007-06-26T19:08:15

Jim Brandt (TPF Conference Chair) and I were talking about the Perl Community Calendar. Eventually we want to use the Google Calendar as a central data store to which anyone can add and update events, and then create various feeds from it (Jim or I can both add people to the calendar's editors if you want to add events. The trick is getting the data back out and figuring out what to include in which feed (for instance, maybe Lisbon.pm wants just the events in Portugal, but also the major events such as YAPC).

It's only a lack of free time that prevents me from getting right on this. If someone else wants to solve this, I could find some free subscriptions to TPR, even though the solution should work for any Google Calendar.

Here's the quick script I wrote just to see if I could get the data programmatically and what It would look like. I haven't investigated too deeply, but you see that Net::Google::Calendar's body method returns the data in a big string rather than in the separated form in which someone enters the separate parts.

This code is free for you to use anyway that you like, even if not for this problem:

#!/usr/bin/perl
use strict;

use Data::Dumper; use Template;

use Net::Google::Calendar;

my $url = "http://www.google.com/calendar/feeds/ngctmrd1cac35061mrjt3hpgng%40group.calendar.google.com/public/basic";

my $cal = Net::Google::Calendar->new( url => $url );

my @entries = ();

foreach my $event ( $cal->get_events ) { my $hash = {}; $hash->{title} = $event->title; my $body = $event->content->body;

print $body, "\n\n\n"; $body =~ s/ / /g; $hash->{description} = do { $body =~ s/(?:
\s*)*Event Description:\s+(.*)\s*//; $1 }; $hash->{status} = do { $body =~ s/(?:
\s*)*Event Status:\s+(.*)\s*//; $1 }; $hash->{where} = do { $body =~ s/(?:
\s*)*Where:\s+(.*)\s*//; $1 }; $hash->{when} = do { $body =~ s/When:\s+(.*)\s*//; $1 };

$hash->{when} =~ s/
Replaces.*//;

push @entries, $hash; }

my $tt = Template->new();

my $template = <<"TT";



The Perl Review: Community Events Calendar http://www.theperlreview.com/community_calendar

[% FOREACH event IN entries %] [% event.title %] [% event.description %] [% END %]



TT

$tt->process( \$template, { entries => \@entries } );


Confusion with $event-content-body

Limbic Region on 2007-07-06T06:15:50

When I started working on this earlier today (blind), I assumed from looking at your code and comments along with Jim's starter code that $event->content->body indeed returned everything in one huge chunk.

Once I got home and was able to test it out, my experience disagreed with those assumptions. In fact, I couldn't get much more than id(), title(), and content()->body() to work. The output of content()->body() though is much different then is implied above.

As I pointed out in a reply to you over in Jim's blog, I have already provided working code but I am truly confused as to what your code (and his) was based on.

I feel like I am missing the boat here.

Cheers,
Limbic~Region

Re:Confusion with $event-content-body

brian_d_foy on 2007-07-06T06:39:21

You're just missing the fact that I spent about five minutes thinking about it then moved on in life, which is why I posted it here. For what I did, the body is just what my code implies. If you used a different feed, then it comes out differently. *shrug*

Ahhhh, I get it now

Limbic Region on 2007-07-06T06:31:25

Minor difference between your code and Jim's

group.calendar.google.com/public/basic

vs

group.calendar.google.com/public/full

I focused on full which required me to figure out why Net::Google::Calendar is broken since not all the meta data is stuffed into body() in that view.

In any case, I hope the code I provided is useful.