#!/usr/bin/perl # Tim Watson # Feb 2008 use strict; use XML::DOM; use Device::SerialPort; my $port = Device::SerialPort->new("/dev/ttyUSB0"); $port->databits(8); $port->baudrate(9600); $port->parity("none"); $port->stopbits(1); sleep(1); my $file = 'http://www.google.com/ig/api?weather=05464&hl=en'; my $rdymsg = "Ready"; my $parser = XML::DOM::Parser->new(); my $doc = $parser->parsefile($file); my $disp = 1; my $output = ''; foreach my $species ($doc->getElementsByTagName('forecast_conditions')){ # day - line 1 frame 1 my $day = uc($species->getElementsByTagName('day_of_week')->item(0)->getAttribute('data')); $output .= $disp . "11" . $day . "\n"; # conditions = line 1 frame 2 + 3 my $cond = uc($species->getElementsByTagName('condition')->item(0)->getAttribute('data')); $cond =~ s/MOSTLY/M/; $cond =~ s/PARTLY/P/; $cond =~ s/ SHOWERS//; $cond =~ s/CHANCE OF/C/; $output .= $disp . "12" . $cond . "\n"; $output .= $disp . "13" . $cond . "\n"; # high temp - line 2 frame 2 my $high = uc($species->getElementsByTagName('high')->item(0)->getAttribute('data')); if (($high > -10 ) && ($high < 10)) { $high = " " . $high; } if (($high >= 0) && ($high < 100)) { $high = " " . $high; } $output .= $disp . "22H" . $high . "\n"; # low temp - line 2 frame 3 my $llow = uc($species->getElementsByTagName('low')->item(0)->getAttribute('data')); if (($llow > -10 ) && ($llow < 10)) { $llow = " " . $llow; } if (($llow >= 0) && ($llow < 100)) { $llow = " " . $llow; } $output .= $disp . "23L" . $llow . "\n"; $disp++; } # Doesn't like my long string at a time my @buffer = split(/\n/,$output); foreach my $line (@buffer) { $port->write($line . "\n"); #print "$line\n"; select(undef,undef,undef,0.05); # sleep just enough }