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

Hi Darren, Thanks for the quick reply. The script fetches the description ok, but unfortunately not the actual temperatures. I can't get it to display the description in html, not sure if that is because of the missing enclosing tags "abcdef"; or the page itself. I'll do a mock js results page to fix that side of things. thanks again, pip

Replies are listed 'Best First'.
Re^3: weather fetching script
by McDarren (Abbot) on Jul 13, 2006 at 12:13 UTC
    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 :)

      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?) ;)