pip has asked for the wisdom of the Perl Monks concerning the following question:
Desired output example, generated in weather.js:#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); open(W, "weather.js"); @lines = <W>; close(W); $out = join('', @lines); if (scalar(@lines) < 3 or -M "weather.js" > 0.25) { use LWP::UserAgent; $ua = LWP::UserAgent->new(); $ua->timeout(60); $request = HTTP::Request->new('GET', 'http://www.bom.gov.au/cgi-bin/wr +ap_fwo.pl?IDS10034.txt'); $res = $ua->request($request); if ($res->is_error) { $str = $res->message; } else { $str = $res->content; } $str =~ s/^.*IDS1003401//s; $str =~ s/HEADLINE.*?$//s; if ($str =~ /:\s+(.*?)\n\n/s) { $adeldesc = $1; $adeldesc =~ s/\n//g; } if ($str =~ /Adelaide City\s+(.*?)\s+Max\s+(\d+)/s) { $adelmax = $2; } if ($str =~ /Noarlunga\s+(.*?)\s+Max\s+(\d+)/s) { $norlmax = $2; } $out =<<EOF; var adeldesc = "$adeldesc"; var adelmax = "$adelmax"; var norlmax = "$norlmax"; EOF open(W, ">weather.js"); print W $out; close(W); } print <<EOF; Content-Type: text/x-javascript Pragma: no-cache Cache-Control: no-cache Expires: -1 $out EOF
var adeldesc = "Fine, mild and sunny afternoon. Moderate southeast win +ds and afresh afternoon sea breeze."; var adelmax = "29"; var norlmax = "32"; var elizmax = "26"; (a new field, which I'd love to have)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: weather fetching script
by McDarren (Abbot) on Jul 13, 2006 at 05:26 UTC | |
by pip (Novice) on Jul 13, 2006 at 11:46 UTC | |
by McDarren (Abbot) on Jul 13, 2006 at 12:13 UTC | |
by pip (Novice) on Jul 14, 2006 at 05:50 UTC | |
by McDarren (Abbot) on Jul 14, 2006 at 06:16 UTC | |
| |
| |
|
Re: weather fetching script
by cwry (Monk) on Jul 13, 2006 at 05:07 UTC | |
by pip (Novice) on Jul 13, 2006 at 11:52 UTC |