Blessings, Brothers,
My weather fetching script on my website no longer works.
How it normally worked: html page generated form 'get' request invocing the script, which generated weather results, saved as file with js extension.
Problem: Script still logs into bom (buero of met, australia), but is unable to fetch, or generate the correct data.
Any help is most appreciated...I tinkered around with it, but to no success :(
The script:
#!/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
Desired output example, generated in weather.js:
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)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.