Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Automated downloading of NOAA radar images

by Scott7477 (Chaplain)
on Jun 13, 2007 at 21:34 UTC ( [id://621102]=CUFP: print w/replies, xml ) Need Help??

Inspired by Develop your own weather maps and alerts with Perl and GD, I have put together a script which downloads the base radar image from a specific site at a specified interval.
use strict; use LWP::Simple; use POSIX; my $refresh = 1800; do { my $base="http://radar.weather.gov/ridge/RadarImg/N0R/MTX_N0R_0.gi +f"; my $timestring = strftime( "%Y%m%d_%H%M%S", gmtime() ); my $savefilename = "SLCRadar_".$timestring.".gif"; my $status = getstore($base,$savefilename); print $status."\n" ; sleep $refresh; } while ($refresh);

Replies are listed 'Best First'.
Re: Automated downloading of NOAA radar images
by merlyn (Sage) on Jun 13, 2007 at 23:28 UTC
    I don't see $refresh changing in the loop, so I'm not sure why you have a do-while $refresh. If you just want an infinite loop, a naked block with a redo at the end will do nice.
      Thanks for the tip, merlyn, I have "refactored" my code as follows:

      use strict; use LWP::Simple; use POSIX; my $refresh = 1800; { &imagegrab; sleep $refresh; redo; } sub imagegrab { my $base="http://radar.weather.gov/ridge/RadarImg/N0R/MTX_N0R_0.gi +f"; my $timestring = strftime( "%Y%m%d_%H%M%S", gmtime() ); my $savefilename = "SLCRadar_".$timestring.".gif"; my $status = getstore($base,$savefilename); print $status."\n" ; }

      It does seem a cleaner way to handle this...
      I know it doesn't really matter in this case but generally speaking isn't a while(1) block a better choice for infinite looping? I would think performance would be the same (I assume a while block collapses down to a naked-redo block) which leaves code readability. And letting the reader know at the beginning of the block that it's an infinite loop is a lot better than forcing the reader to wade through several lines of code before discovering that. Is that a good assessment or am I missing something?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://621102]
Approved by Joost
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found