[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Fwd: iCal::Parser - or how to iterate through this hash?
Forwarding Brian's message while Brian and I try to figure out why his post didn't go straight through...
j
-------- Original Message --------
Subject: [Fwd: iCal::Parser - or how to iterate through this hash?]
Date: Wed, 22 Feb 2006 22:10:42 -0800
From: Brian Wiese <bwiese@cotse.com>
To: jay@jays.net
Any idea why this didn't go through to the list?
Brian
-------- Original Message --------
Subject: iCal::Parser - or how to iterate through this hash?
Date: Wed, 22 Feb 2006 09:47:23 -0800
From: Brian Wiese <bwiese@cotse.com>
To: Perl Mongers of Omaha, Nebraska USA <omaha-pm@pm.org>
I've been out of touch with perl for some time now, but have remained on
the list and now I need some help. =) For a little project, I'd like to
parse my iCal files and (eventually) populate a mysql db. (I thought it
sounded simple too!) I've been messing with out iCal::Parser (since it
sounds good) but am in over my head and am thinking maybe there is an
easier route?
http://search.cpan.org/~rfrankel/iCal-Parser-1.11/lib/iCal/Parser.pm
{
calendars=>[\%cal, ...],
events=>{yyyy=>{mm=>{dd}=>{UID=>\%event}}
todos=>[\%todo, ...]
}
I'd just like to iterate over each of my events/todo items and then
populate a db. First issue is how to access this reference hash?
Secondly, to get to each event - can I get an Iterator or do I need to
search through every yyyy-mm-dd-uid combination?
Also, I used a dumper to see what's inside... and it's ugly, much more
complicated than the actual .ics file itself. Am I going in the wrong
direction? Easier to just regex each line myself?
Thanks,
Brian
my test.ics file (from Sunbird - still a little buggy at times)
bw@freedom:proj $ cat test.ics
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.0//EN
BEGIN:VEVENT
CREATED:20060207T005839Z
LAST-MODIFIED:20060207T005839Z
DTSTAMP:20060207T005839Z
UID:uuid:1139273884656
SUMMARY:title Project Discussion
PRIORITY:5
STATUS:CONFIRMED
CLASS:PUBLIC
DTSTART:20060206T120000
DTEND:20060206T125000
LOCATION:location SP408\, NPS\, Monterey\, CA 93943 (no geo)
CATEGORIES:Issues
DESCRIPTION:description Plan out project and subprojet ideas for Mobile
Alert\nmain topics: profile\, calendar\, \ntesting out vcal format -
brian
URL:http://sharedonline.com/nps/
BEGIN:VALARM
TRIGGER;VALUE=DURATION:-PT30M
X-EMAILADDRESS:bwiese@example.com
END:VALARM
END:VEVENT
END:VCALENDAR
my ical2sql start...
#!/usr/bin/perl -w
use strict;
use iCal::Parser;
# http://www.codecomments.com/showthread.php?postid=2514293
use Data::Dumper;
my $icalFile = "test.ics";
open(INFILE,$icalFile) or die "could not open $icalFile: $!";
my $c = 1;
while(<INFILE>) { print "$c: $_"; $c++; }
close INFILE;
print "-- using iCal:Parser --\n";
my $parser=iCal::Parser->new();
my $hash=$parser->parse($icalFile);
open(DUMPFILE, ">ical.dump.txt");
print DUMPFILE Dumper($parser); # from Data::Dumper
close DUMPFILE;
print "SUMMARY: ";
# http://search.cpan.org/~rfrankel/iCal-Parser-1.11/lib/iCal/Parser.pm
print
$hash->{events}->{2006}->{2}->{6}->{'uuid:1139273884656'}->{SUMMARY} . "\n";
# Don't know what to do with this stuff here, probably need to READ more. =)
#my @hkeys = keys $hash->{\%cal};
#my @hvals = values $hash->{\%cal};
#print @hkeys;
#while(@hkeys) {
# print pop(@hkeys), '=', pop(@hvals), "\n";
#}
--
bwiese[at]cotse.com | brianwiese.net | 402.297.9392
"What we do in life echoes in eternity" - Gladiator