I am working on an EXE version , I'll update more when I get it done
Monday, April 17, 2006
programming: Perl,Google Calendar and the Ipod
So, I wanted an easy way to update the calendars from my google account to my ipod. Since I don't sync my calendar with software on my ipod, I manually copy the ical files to the calendar folder and that works fine. But in google calendar, that means clicking on each calendar, clicking on a tab, clicking on the ICAL link and saving the file to the ipod. I currently have 2 calendars, so updating my ipod will be a hassle. In comes my favorite superglue programming language, Perl! This script automates the process and with one double click the script downloads and saves my 2 calendars to my ipod.
Yeah, but this is really, really easy with LWP. All you have to know are the links to your ical files and where you want to put them. I wrote a script to do this very same thing.
ReplyDelete#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use FileHandle;
# welcome message
print "\n\tTime to get your calendars off of google!\n\n\tMake sure your USB drive is plugged in!!\n\n";
# flush the output buffer
$|=1;
# constants
my $storageHome = "E:/Calendars";
my %addresses = (
MyFirstCal => 'http://...',
);
# connect to google, get the ical file, save to portable disk
my $fetcher = LWP::UserAgent->new();
$fetcher->agent("CalendarFetcher/1.0");
foreach my $calendar (keys %addresses) {
my $calLocalFileName = ">".$storageHome."/".$calendar.".ics";
my $calRemoteFileName = $addresses{$calendar};
my $req = HTTP::Request->new(GET => $calRemoteFileName);
print "Fetching $calendar from google...";
my $res = $fetcher->request($req);
print "DONE.\n";
if ($res->is_success) {
my $f = new FileHandle $calLocalFileName;
if ($f) {
print "\tSaving $calLocalFileName...";
my $ical = $res->content;
$ical =~ s/\r\n/\n/gs;
print $f $ical;
undef $f;
print "DONE\n";
} else {
print "Do you have your USB drive plugged in?\n";
exit(0);
}
}
}