#!/usr/bin/perl
# water2rss.pl - create an RSS feed from my water collection
# Eric Lease Morgan
# May 25, 2011 - first cut
# configure
use constant DSN => 'dbi:mysql:water:localhost';
use constant USERNAME => 'nobody';
use constant PASSWORD => 'nobody';
# require
use strict;
use DBI;
use DateTime;
# start the output
print '';
print '';
print '';
print "Water de Jour";
print 'http://infomotions.com/water/index.xml';
print 'A randomly selected water from the collection';
print 'en-us';
print 'Copyright '. DateTime->now->year . ', Eric Lease Morgan';
print 'make-rss.pl';
print 'water';
print 'eric_morgan@infomotions.com (Eric Lease Morgan)';
print 'eric_morgan@infomotions.com (Eric Lease Morgan)';
print '' . &buildDate( DateTime->now->ymd ) . '';
# search
my $dbh = DBI->connect( DSN, USERNAME, PASSWORD );
my $sql = 'SELECT * FROM waters';
my $waters = $dbh->selectall_arrayref( $sql, { Slice => {} } );
# process each result
foreach my $water ( @$waters ) {
# extract
my $id = $water->{ 'water_id' };
my $name = $water->{ 'name' };
my $year = $water->{ 'year' };
my $month = $water->{ 'month' };
my $day = $water->{ 'day' };
if ( ! $day ) { $day = '01' }
my $description = $water->{ 'description' };
my $lat = $water->{ 'lat' };
my $lng = $water->{ 'lng' };
# thumbnail
my $thumbnail = $name;
$thumbnail =~ /^(\w+) /;
$thumbnail = "http://infomotions.com/water/thumbnails/$1-$id.jpg";
# google map
my $map = "Map it";
# echo/debug
#print " id = $id\n";
#print " name = $name\n";
#print " year = $year\n";
#print " month = $month\n";
#print " day = $day\n";
#print " description = $description\n";
#print " latitude = $lat\n";
#print " longitude = $lng\n";
#print " thumbnail = $thumbnail\n";
#print " map = $map\n";
#print "\n";
# build the rss item
print '- ';
print "$name";
print "http://infomotions.com/water/index.xml?cmd=getwater&id=$id";
print "
 $map |
$description
]]>";
print '' . &buildDate( $year . '-' . $month . '-' . $day ) . '';
print "http://infomotions.com/water/index.xml?cmd=getwater&id=$id";
print '';
}
# done
print '';
exit;
sub buildDate {
my $date = shift;
my ($year, $month, $day) = split('-', $date);
my $dt = DateTime->new(year => $year, month => $month, day => $day, time_zone => 'America/Indianapolis');
my $rv = $dt->strftime("%a, %d %b %Y %H:%M:%S %z");
return $rv;
}