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

[coldsync-hackers] Adding events to your datebook



Forgive me if I seem to keep coming up with rather basic questions. I'm
getting rather frustrated that each of the different Palm Perl modules
seems to have a subtly different API, and that it requires not a little
magic to get things to work. I'm also a little at a loss to grasp all of
the global variables that these modules seem to casually export. I guess
I need to read the conduit tutorial another time or two.

Anyways, what is attached is a slightly modified version of a conduit
called "philcon" that appears on the coldsync web site. The purpose of
that conduit was to add a very specific list of events to a datebook,
once, and never again. If you run it again, by the way, the events get
added again, and show up twice in your datebook.

The attached conduit checks to see if the event is already there. More
specifically, it checks to see if an event with the same name appears on
the same date. Which is not necessarily the same thing.

Also, this conduit is only for annual events. But it may give some folks
some ideas to take this a little farther.

One interesting side note. While I was working on this, I screwed up and
got days and months reversed. Coldsync quite happily told my Visor to
add events on the 2nd day of the 16th month of 2001. And my Visor quite
happily added the event. The only way to get to the event was to search
for it, since there was no other way to get to the day in question. I
was also able to add an event to the 0th of February.

Anyways, here's the code:


-- 
Rich Bowen <rbowen@rcbowen.com>
Come see me at Apachecon! -- http://www.apachecon.com/
#!/usr/bin/perl
use Palm::Datebook;

my $pdb = new Palm::PDB;

$pdb->Load("$ENV{HOME}/.palm/backup/DatebookDB.pdb");
my $datebook;

foreach my $event ( @{$pdb->{records}} )     {
     $datebook->{ $event->{description} } = $event;
}

while (<DATA>)
{
	my ($day, $month, $year, $desc, $note) = split /~/, $_;
     chomp($note);

     next if ( defined ( $datebook->{$desc} ) 
              && ( $datebook->{$desc}->{day} == $day )
              && ( $datebook->{$desc}->{month} == $month ) );
          
     my $record = $pdb->append_Record;
	$record->{"day"} = $day;
	$record->{"month"} = $month;
	$record->{"year"} = $year;
	$record->{"start_hour"} = 255;
	$record->{"start_minute"} = 255;
	$record->{"end_hour"} = 255;
	$record->{"end_minute"} = 255;
	$record->{"description"} = $desc;
	$record->{"note"} = "$note";
	$record->{"attributes"}{"dirty"} = 1;
	$record->{"category"} = 0;
     $record->{'repeat'} = { 'frequency' => 1, 
                            'type' => 5,
                            'unknown' => 0 };
     $record->{'alarm'} = {};                              

}

$pdb->Write("/tmp/DatebookDB.pdb");

__DATA__
31~1~2001~Nauru Independence Day~
1~2~2001~Robinson Crusoe Day~USA
2~2~2001~Candlemas~Sweden, Switzerland and Liechtenstein
2~2~2001~Groundhog Day~USA, Canada, and Switzerland
3~2~2001~Heroes' Day~Mozambique
10~2~2001~Feast of St Paul's Shipwreck~Malta
11~11~2001~Armed Forces Day~Liberia
11~2~2001~Empire Day~Japan
11~2~2001~Mothers' Day~Norway
11~2~2001~Thomas Edison's Birthday~
14~2~2001~St. Valentine's Day~
15~2~2001~National Flag of Canada Day~Canada
15~2~2001~Rose Monday~Bolivia
15~2~2001~Spanish-Americal War Memorial Day~Massachusetts, USA
15~2~2001~Susan B. Anthony Day~Florida, USA
16~2~2001~Gion Matsuri~Japan
16~2~2001~Lithuania Independence Day~1918
17~2~2001~National Public Science Day~USA
18~2~2001~Gambia Independence Day~