#!/bin/perl # libby.miller@bristol.ac.uk 2000-01-23 # gets dates from Palm datebook database, # e.g. /home/user/.jpilot/DatebookDB.pdb # and converts to RDF 'hybrid' iCalendar format # http://ilrt.org/discovery/2001/06/schemas/ical-full/hybrid.rdf # # see also RDF calendar taskforce # http://ilrt.org/discovery/2001/04/calendar/ # # useage: ./date2rdf.pl '20000123' 'mailto:mailaddr' 'GMT' # # where the first arg is the date and the second is person id # ./date2rdf.pl gives you all the dates (no person id) # does not print out private records (see priv!=1 below) # if no tz, defaults to UTC # # # requires the Palm perl modules # # http://search.cpan.org/doc/ARENSB/p5-Palm-1.1.5/Palm/PDB.pm # use Palm::PDB; use Palm::Datebook; my $pdb = new Palm::PDB; my $dbfile="$ENV{HOME}/.jpilot/DatebookDB.pdb"; #my $dbfile="DatebookDB.pdb"; $pdb->Load($dbfile) || die print "oops! no $dbfile found\n"; $pdb->{sort}; my $label; my $labelt; my $dlabel=undef; my $mbox="none"; $dlabel=$ARGV[0]; $mbox=$ARGV[1]; my $tz=$ARGV[2]; my $tzns="http://ilrt.org/discovery/2001/06/content/tz/"; if($tz eq ""){ $tz="UTC"; } if($mbox eq ""){ $mbox="none"; } my $label; my $labelt; if($dlabel eq "today"){ ($sec, $min, $hour, $mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $m=$mon+1; $y=$year+1900; $d=$mday; if($m<10){ $m="0".$m; } if($d<10){ $d="0".$d; } $dlabel=$y.$m.$d; #print $dlabel; } my $buf; $buf=" \n"; $buf=$buf."\n\n\t "; ## creation information $buf=$buf."\n\t\t"; $buf=$buf."\n\t\tGenerated Calendar RDF for $mbox for the date $dlabel"; $buf=$buf."\n\t\t"; $buf=$buf."\n\t\t$dlabel\n"; my $i=0; foreach $record (@{$pdb->{records}}){ my $record = {}; $record = $pdb->{records}[$i]; $i++; my $time; my $day; my $date; my $start; my $end; my $endm; my $location; my $desc; chomp; ($time, $desc, $location, $note) = split /\n/, $_, 4; my $m=$record->{"month"}; my $d=$record->{"day"}; if($m<10){ $m="0".$m; } if($d<10){ $d="0".$d; } $label=$record->{"year"}."-".$m."-".$d; $labelt=$record->{"year"}.$m.$d; #print "\nlabel is ".$label."\n"; #print "\nlabelt is ".$labelt."\n"; #print "\ndlabel is ".$dlabel."\n"; ##don't want to print private ones my $priv=$record->{"attributes"}{"private"}; ####remove this part to show all if($priv!=1){ if( ($dlabel eq $labelt) || ($dlabel==undef)){ $buf=$buf."\n\t\t\n\t\t\t"; $buf=$buf."\n\t\t\t\t " . $record->{"description"} . ""; $buf=$buf."\n\t\t\t\t\n\t\t\t\t\t"; if($tz eq "UTC"){ $buf=$buf."\n\t\t\t\t\t".$dlabel."T".$record->{"start_hour"}.$record->{"start_minute"}."00Z"; }else{ $buf=$buf."\n\t\t\t\t\t "; $buf=$buf."\n\t\t\t\t\t".$dlabel."T".$record->{"start_hour"}.$record->{"start_minute"}."00"; } $buf=$buf."\n\t\t\t\t\t ".$record->{"start_hour"}.""; $buf=$buf."\n\t\t\t\t\t ".$record->{"start_minute"}.""; $buf=$buf."\n\t\t\t\t\t\n\t\t\t\t"; $buf=$buf."\n\t\t\t\t\n\t\t\t\t\t"; if($tz eq "UTC"){ $buf=$buf."\n\t\t\t\t\t".$dlabel."T".$record->{"end_hour"}.$record->{"end_minute"}."00Z"; }else{ $buf=$buf."\n\t\t\t\t\t "; $buf=$buf."\n\t\t\t\t\t".$dlabel."T".$record->{"end_hour"}.$record->{"end_minute"}."00"; } $buf=$buf."\n\t\t\t\t\t ".$record->{"end_hour"}.""; $buf=$buf."\n\t\t\t\t\t ".$record->{"end_minute"}.""; $buf=$buf."\n\t\t\t\t\t\n\t\t\t\t"; if($mbox ne "none"){ $buf=$buf."\n\t\t\t\t\n\t\t\t\t\t"; $buf=$buf."\n\t\t\t\t\t"; $buf=$buf."\n\t\t\t\t\t"; $buf=$buf."\n\t\t\t\t\t\n\t\t\t\t"; } else{ #print "UNDEF"; } $buf=$buf."\n\t\t\t\n\t\t"; } } } $buf=$buf."\n\t\n"; print RDF $buf; close RDF; #$buf=~ s/(.*)<(.*)/$1\<$2/g; #$buf=~ s/(.*)>(.*)/$1\>$2/g; #$buf=~ s/(.*)<(.*)>(.*)/$1\<$2\>$3/g; print $buf;