[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Fwd: iCal::Parser - or how to iterate through this hash?



I used Tie::iCal - http://search.cpan.org/~bsdz/Tie-iCal-0.13/

Home office users schedule events via web interface or events are generated by 
system.  Remote users sync calendars over vpn using Thunderbird / Calendar 
extension and webdav.  

Just showing $event_date retrieval here to point out ics expecting 'YYYYMMDD' 
+ time format for those dates.

Note - around "tie %cal" there should be some file locking so multiple 
instances don't stomp on each other.  Tie::iCal can use Tie::File flock (see 
documentation).

Bottom code snippet shows access to internal hash structure.

Dutch

--------------------------------------------------------
#
# yes, there is only one row per cust in the db :-)
#
my $event_date = $dbh->selectrow_array("
SELECT
    to_char(schedule_next_date, 'YYYYMMDD')
FROM
    review_schedule
WHERE
    id_cust = $customer_number
");

#
# Please guarantee unique id
#
my $event_id = "scheduled-review-$customer_number-$route";

#
# Should get object returned so can do file locking,
# maybe my $cal_object = tie %cal, -rest of line-
# and then $cal_object->{A}->flock or don't proceed
#
tie %cal, 'Tie::iCal', "/dav/division$div/ics/div$div.ics"
    or die "Failed to tie file: /dav/division$div/ics/div$div.ics\n";

$cal{$event_id} = [
	'VEVENT',
	{
	'SUMMARY' => "BR $customer_number $cust_name",
	'LOCATION' => "$city_state",
	'CLASS' => 'PRIVATE',
	'STATUS' => 'TENTATIVE',
	'DESCRIPTION' => "Route $route Customer $customer_number",
#
# Not really scheduling time, just want event to show up on that day
#
	'DTSTAMP' => $event_date . "T080000",
	'DTSTART' => $event_date . "T080000",
	'DTEND' => $event_date . "T080001"
	}
];

untie %cal;
--------------------------------------------------------
#
# Accessing hash event structure:
#
foreach $key (sort (keys(%cal))) {
    print "$key\n";
    print "$cal{$key}[1]->{SUMMARY}\n";
    print "$cal{$key}[1]->{LOCATION}\n";
    print "$cal{$key}[1]->{DESCRIPTION}\n";
    print "$cal{$key}[1]->{DTSTART}\n";
    print "$cal{$key}[1]->{DTEND}\n\n";
}


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