# ----------------------------------------------------------------------------------------------- # Author: Dean Stringer # Original Release Date: Oct 2002 # # Description/Purpose: # Performs a SQL query against a database in MySQL called 'weblinks' and # returns URLs that have Metadata that match a search string that a user # fills out in the Form or URL that calls this script. # # Dependencies: # Palm::PDB base class for common PDB file elements # Palm::Memo functions for adding/removing Memo field elements # ----------------------------------------------------------------------------------------------- use strict; use Palm::PDB; use Palm::Memo; my $pdb = new Palm::PDB; $pdb->Load("MemoDB.pdb"); # print dump($pdb); my @categories = @{$pdb->{appinfo}{categories}}; my @records = @{$pdb->{records}}; # showCategories(\@categories); # showRecords(\@records, \@categories); my $categoryLabel = 'Blog'; my $catID = fetchCategoryID($categoryLabel, \@categories); if ($catID ne '') { saveCategoryAsRSS(\@records, \@categories, $catID); } else { print "\nNo such Category '$categoryLabel' found in MemoDB!\n"; } #============================================================================== # End of Main, start of subs #============================================================================== sub fetchCategoryID { my ($label, $catRef) = @_; my $foundID = ''; my $count = 0; foreach my $category (@{$catRef}) { if ($category->{name} eq $label) { $foundID = $count; last; } $count++; } return $foundID; } sub saveCategoryAsRSS { #--------------------------------------------------------------------------------------------------- # Build an RSS representation of link data #--------------------------------------------------------------------------------------------------- my ($recordRef, $catRef, $categoryID) = @_; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); my $thisRenderTime = "$mday $months[$mon] " . ($year + 1900) . " $hour:$min:$sec UT"; my $categoryTitle = "DeeKnows Palm Blog"; my $categoryDescription = "A collection of notes authored on my PalmPilot and published using the Radio aggregator."; my $link = 'http://www.deeknow.com/palm-blog.rss'; use XML::RSS; use HTML::Entities; my $rss = new XML::RSS (version => '0.91'); # Add the channel header/definition $rss->channel( title => $categoryTitle, link => $link, language => 'en-nz', description => $categoryDescription, pubDate => $thisRenderTime ); # add an RSS item for each record foreach my $record (@{$recordRef}) { # step through all records looking for category if ($record->{category} eq $categoryID) { my $data = $record->{data}; my $category = @{$catRef}[$record->{category}]->{name}; my $title = "blank"; if ($data =~ /^(.*)\n+([\w\W]*)$/) { $title = $1; $data = $2; } # palm uses the 1st line as a title for memo's $title = HTML::Entities::encode($title); $data = HTML::Entities::encode($data); $rss->add_item( title => $title, link => '', description => $data ); } } print $rss->as_string; } sub showRecords { my ($recordRef, $catRef) = @_; foreach my $record (@{$recordRef}) { my $data = $record->{data}; my $category = @{$catRef}[$record->{category}]->{name}; my $title = "blank"; if ($data =~ /^(.*)\n/) { $title = $1; } # The palm uses the 1st line as a title for memo's print "\nID $record->{id} : Cat $category : $title"; } } sub showCategories { my $catRef = shift; foreach my $cat (@{$catRef}) { print "\nID $cat->{id} : $cat->{name}" if $cat->{name} ne ""; } } sub updateRecords { my $outputFilename = "test.pdb"; # my $newRecord = new_Record Palm::PDB; my $newRecord = $pdb->new_Record( category => '9', id => '12_334', data => "this and that\nhere we go."); $newRecord->{attributes}{dirty} = '0'; $newRecord = $pdb->append_Record; $pdb->Write($outputFilename); }