Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Tuesday June 26, 2007
02:08 PM

Trying to get feeds from Google Calendar

[ #33608 ]

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 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:

use strict;
use Data::Dumper;
use Template;
use  Net::Google::Calendar;
my $url = "";
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/(?:<br>\s*)*Event Description:\s+(.*)\s*//; $1 };
    $hash->{status}      = do { $body =~ s/(?:<br>\s*)*Event Status:\s+(.*)\s*//; $1 };
    $hash->{where}       = do { $body =~ s/(?:<br>\s*)*Where:\s+(.*)\s*//; $1 };
    $hash->{when}        = do { $body =~ s/When:\s+(.*)\s*//; $1 };
    $hash->{when} =~ s/<br>Replaces.*//;
    push @entries, $hash;
my $tt = Template->new();
my $template = <<"TT";
<?xml version="1.0" encoding="ISO-8859-1"?>
<channel rdf:about="">
<title>The Perl Review: Community Events Calendar</title>
[% FOREACH event IN entries %]
<title>[% event.title %]</title>
<description>[% event.description %]</description>
[% END %]
$tt->process( \$template, { entries => \@entries } );

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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 o
    • 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*
  • Minor difference between your code and Jim's


    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.