#!/usr/bin/perl use strict; use Switch; #### Australian weather script for Asterisk (agi-bin script) v1.1 #### Here we change the following settings to change location. #### $url = the BOM site to get the weather from. #### $station = the weather station to use. my $url = "http://www.bom.gov.au/products/IDV60900.shtml"; my $station = "Melbourne Airport"; #### You don't need to change anything below this line #### my $i = 0; my $BOMOUTPUT=`curl --stderr /dev/null $url | grep -A 18 -E ".*left.*>$station<.*"`; chomp($BOMOUTPUT); my @bomoutput=split("\n", $BOMOUTPUT); undef($BOMOUTPUT); print "exec Playback national-weather-service\nexec Playback the-weather-at\n"; if ( @bomoutput[1] =~ /^\s.*\d\d\/(\d\d):(\d)(\d)(..).*/ ) { my $hours = $1; if ( ($4 eq "pm") && ($1 ne "12") ) { $hours = $1 + 12; } print "say number $hours *\n"; if ( "$2$3" > 10 ) { print "say number $2$3 *\n"; } else { print "exec playback digits/0\nsay number $3 *\n"; } } else { print "Failed to get the time\n"; exit 1; } print "exec playback is\n"; if ( @bomoutput[2] =~ /^\s.*>(\d+)\.(\d)<.*/ ) { print "exec Playback wx/temperature\nsay number $1 *\nexec playback wx/point\n"; if ( $2 eq "0" ) { print "exec playback digits/0\nexec playback celsius\n"; } else { print "say number $2 *\nexec playback celsius\n"; } } else { print "Failed to get temp\n"; exit 1; } if ( @bomoutput[4] =~ /^\s.*>(\d+)\.(\d)<.*/ ) { print "exec playback wx/dew-point\nsay number $1 *\nexec playback wx/point\n"; if ( $2 eq "0" ) { print "exec playback digits/0\nexec playback celsius\n"; } else { print "say number $2 *\nexec playback celsius\n"; } } else { print "Failed to get dewpoint\n"; exit 1; } if ( @bomoutput[7] =~ /^\s.*>(.*)<.*/ ) { print "exec playback wx/winds\n"; switch ($1) { case "N" { print "exec playback northerly\nexec playback at\n"; } case "NNE" { print "exec playback north\nexec playback wx/northeast\nexec playback at\n"; } case "NE" { print "exec playback wx/northeast\nexec playback at\n"; } case "ENE" { print "exec playback east\nexec playback wx/northeast\nexec playback at\n"; } case "E" { print "exec playback easterly\nexec playback at\n"; } case "ESE" { print "exec playback east\nexec playback wx/southeast\nexec playback at\n"; } case "SE" { print "exec playback wx/southeast\nexec playback at\n"; } case "SSE" { print "exec playback south\nexec playback wx/southeast\nexec playback at\n"; } case "S" { print "exec playback southerly\nexec playback at\n"; } case "SSW" { print "exec playback south\nexec playback wx/southwest\nexec playbact at\n"; } case "SW" { print "exec playback wx/southwest\nexec playback at\n"; } case "WSW" { print "exec playback west\nexec playback wx/southwest\nexec playback at\n"; } case "W" { print "exec playback westerly\nexec playback at\n"; } case "WNW" { print "exec playback west\nexec playback wx/northwest\nexec playback at\n"; } case "NW" { print "exec playback wx/northwest\nexec playback at\n"; } case "NNW" { print "exec playback north\nexec playback wx/northwest\nexec playback at\n"; } case "CALM" { print "exec playback wx/steady\nexec playback at\n";} } } else { print "Failed to get winddir\n"; exit 1; } if ( @bomoutput[8] =~ /^\s.*>(.*)<.*/ ) { if ( $1 eq "0" ) { print "exec playback digits/0\n"; } else { print "say number \"$1\" *\n"; } } else { print "Failed to get windspeed\n"; exit 1; } if ( @bomoutput[9] =~ /^\s.*>(.*)<.*/ ) { if ( $1 eq "0" ) { print "exec playback wx/gusting-to\nexec playback digits/0\nexec playback kilometers-per-hour\n"; } else { print "exec playback wx/gusting-to\nsay number $1 *\nexec playback kilometers-per-hour\n"; } } else { print "Failed to get windgust\n"; exit 1; } if ( @bomoutput[12] =~ /^\s.*>(\d+).(\d)<.*/ ) { print "exec playback wx/barometer\nsay number $1 *\nexec playback wx/point\n"; if ( $2 eq "0" ) { print "exec playback digits/0\nexec playback hectopascal\n"; } else { print "say number $2 *\nexec playback hectopascal\n"; } } else { print "Failed to get hpa\n"; exit 1; }