in reply to Re^2: weather fetching script
in thread weather fetching script

Okay, well that's because the content on layout of the page actually changes according to the time of day. Later in the afternoon they start including the forecast overnight minimums as well. Given that I used to work for them, I should have known this - but hey, it was a few years ago ;)

Anyway, this is easy to get around. Given that you aren't interested in the minimums, you can simply alter the pattern match on line 40 to read as follows:

if ($line =~ /^([\w\s]+):.*?Max\s+(\d+)/) {

The change is that we include a non-greedy .* to skip over anything until it reaches "Max".

With that change (and the current content as at 9:30PM CST), I get:

var adeldesc = Fine and cool with increasing high cloud. Moderate eas +t to northeast winds. var mtbkmax = "9" var noarmax = "11" var adelmax = "10" var elizmax = "11"

Cheers,
Darren :)

Replies are listed 'Best First'.
Re^4: weather fetching script
by pip (Novice) on Jul 14, 2006 at 05:50 UTC
    Hi Darren, Thanks for the mod for the script, temps now show up. Sorry for being a pain...but how can I firstly: get the description being shown in "quotation marks" ? (html page shows errors if it doesn't have them)and secondarily: how do I get the script to write to /home/aml33704/public_html/ ? (Can't get the results to show unless outside cgi-bin) I am very grateful for your help! cheers, pip
      "..get the description being shown in "quotation marks" ?"

      Oh, I hadn't noticed that... you need to change line 46 to read:

      my $out = qq(var adeldesc = "$adeldesc"\n);
      The use of 'qq' allows us to use double-quotes within the string, and also ensures that the variables are correctly interpolated.

      "how do I get the script to write to /home/aml33704/public_html/"

      Well, you simply change the destination in the open statement to include the full path to the file. I'd do something like this:

      my $outfile = '/home/aml33704/public_html/weather.js';
      ..and then:
      open W, ">", $outfile or die "Could not open $outfile for writing:$!\n +";

      Cheers,
      Darren :)

      (By the way, which address do I mail my invoice to?) ;)

        You're the man Darren, Thanks a bunch, everything working fine!...this script really bugged me. I am happy to shout you a drink when you're in Adelaide. I would also be happy to paypal some appreciation for your efforts. cheers, pip
        Hi Darren, I was just wondering ...when the script outputs its description, only the 1st line of the sentence is displayed, even so the bom txt (sometimes) contains another line. Example: Script output: Fine and cool to mild day with increasing high cloud. Light winds, chiefly BOM txt output: Fine and cool to mild day with increasing high cloud. Light winds, chiefly northeast to northwest. Question: Is it possible to display all of the description, regardles if 1 or 2 sentences, and have 'precis' act as the 'full stop'of the description? cheers, pip