It's storm season. Here is a quick hack to get the latest NOAA weather radar photo for your area. It is possible to get up to 10 images for a local, and put them in a loop....I didn't do that. :-)

Also, I didn't bother to do the download thru a fork or thread, so the gui "blocks" while downloading the smallish ~ 35k gif files. I have a "cheap" "please wait indicator".

But if you just want a quick look at the current radar in your area, this works.

Update: I put my location as default when you just hit the Ok button without making a selection, but you can change it to your own. Uncomment the "print $loc[0]\n" line, and get your number, and substitute it for the 77.

#!/usr/bin/perl -w use strict; use Tk; use Tk::JPEG; use LWP::Simple; use MIME::Base64; $|=1; my %loc; my ($state,$city); my $mw = MainWindow->new(); my $tl; setup_selector(); #national overview map my $URLN = 'http://weather.noaa.gov/radar/images/DS.74rcm/AR.conus/lat +est.gif'; my $baseurl = 'http://weather.noaa.gov/radar/images/DS.p19r0/SI.'; my $canvas = $mw->Scrolled('Canvas', -width, 620, -height, 500, -scrollbars, 'osoe', -scrollregion=>[0,0,620,620], -bg => 'black', )->pack(); my $display = $canvas->createImage(0,0, -image =>'', ); my $bframe = $mw->Frame()->pack(-fill =>'x'); $bframe->Button(-text => 'Quit', -command => [destroy => $mw]) ->pack(-side => 'right', -padx => 10); $bframe->Button(-text => 'Local', -command => sub{ select_loc(); } )->pack(-side => 'left', -padx => 10); my $loclab = $bframe->Label(-text => 'Please Select') ->pack(-side => 'left', -padx => 10, -expand => 1); $bframe->Button(-text => 'National', -command => sub{ $loclab->configure(-text=>'Please Wait while loading'); $mw->update; my $nimage = get_latest($URLN); $canvas->itemconfigure($display, -image => $nimage, -anchor => + 'nw',); $loclab->configure(-text =>'National'); } )->pack(-side => 'left', -padx => 10); MainLoop; ###################################################################### +####33 sub get_latest{ my $url = shift; my $content_bin = get($url); my $content = encode_base64($content_bin); my $image = $mw->Photo(-data => $content); return $image; } ###################################################################### +##### sub setup_selector{ #setup localities selector while(<DATA>){ chomp; my ($state,$city,$ident) = split /:/,$_; $loc{$state}{$city} = $ident; } $tl = $mw->Toplevel(); $tl->overrideredirect(1); $tl->withdraw; $tl->title("Localities"); #Create the listbox and insert the list of choices in to it my $lb = $tl->Scrolled("Listbox", -scrollbars => "osoe", -height => 20, -width => 35, -selectmode => "single") ->pack(); foreach my $state( sort keys %loc){ foreach my $city (sort keys %{$loc{$state}}){ $lb->insert("end", "$state--$city"); } } $tl->Button(-text => "Ok", -command => sub { my @loc = $lb->curselection(); $loc[0] ||= 77; #defaults to Michigan Detroit #print $loc[0],"\n"; my $loc1 = $lb->get($loc[0]); ($state,$city) = split /--/,$loc1; my $loc = $loc{$state}{$city}; my $url = "$baseurl$loc/latest.gif"; $loclab->configure(-text=>'Please Wait while loading'); $mw->update; my $image = get_latest($url); $canvas->itemconfigure($display, -image => $image, -anchor => 'n +w',); $loclab->configure(-text =>"$state $city "); $tl->withdraw; })->pack; } ###################################################################### +##### sub select_loc{ CenterWindow($tl,225,400); $tl->deiconify; $tl->raise; } ###################################################################### +## sub CenterWindow { my($window, $width, $height) = @_; $window->idletasks; $width = $window->reqwidth unless $width; $height = $window->reqheight unless $height; my $x = int(($window->screenwidth / 2) - ($width / 2)); my $y = int(($window->screenheight / 2) - ($height / 2)); $window->geometry("=${width}x${height}+${x}+${y}"); } ###################################################################### +#### __DATA__ Alabama:Birmingham:kmbx Alabama:E. Alabama:kmxx Alabama:Fort Rucker:keox Alabama:Mobile:kmob Alabama:N. Alabama:khtx Alaska:Bethel:pabc Alaska:Biokra Is.:pacg Alaska:Fairbanks:papd Alaska:Kenai:pahg Alaska:King Salmon:pakc Alaska:Middleton Is.:paih Alaska:Nome:paec Alaska:Pedro Dome:papd Alaska:Sitka:pacg Arizona:Flagstaff:kfsx Arizona:Phoenix:kiwa Arizona:Tuscon:kemx Arizona:Yuma:kyux Arkansas:Little Rock:klzk Arkansas:W. Ark./Ft. Smith:ksrx California:Beale AFB:kbbx California:Edwards AFB:keyx California:Eureka:kbhx California:Hanford:khnx California:Los Angeles:kvtx California:Sacramento:kdax California:San Diego:knkx California:San Francisco:kmux California:San Joaquin Vly.:khnx California:Santa Ana Mnts.:ksox California:Vandenberg AFB:kvbx Colorado:Denver/Boulder:kftg Colorado:Grand Junction:kgjx Colorado:Pueblo:kpux Delaware:Dover AFB:kdox Florida:Eglin AFB:kevx Florida:Jacksonville:kjax Florida:Key West:kbyx Florida:Melbourne:kmlb Florida:Miami:kamx Florida:NW Florida:kevx Florida:Tallahassee:ktlh Florida:Tampa Bay Area:ktbw Georgia:Atlanta:kffc Georgia:Moody AFB:kvax Georgia:Peachtree City:kffc Georgia:Robins AFB:kjgx Guam:Anderson AFB:pgua Hawaii:Kauai:phki Hawaii:Kohala:phkm Hawaii:Molokai:phmo Hawaii:South Shore:phwa Idaho:Boise:kcbx Idaho:Pocatello:ksfx Illinois:Central IL:kilx Illinois:Chicago:klot Indiana:Evansville:kvwx Indiana:Indianapolis:kind Indiana:N. Indiana:kiwx Iowa:Des Moines:kdmx Iowa:Quad Cities:kdvn Kansas:Dodge City:kddc Kansas:Goodland:kgld Kansas:Topeka:ktwx Kansas:Wichita:kict Kentucky:Fort Cambell:khpx Kentucky:Jackson:kjkl Kentucky:Louisville:klvx Kentucky:Paducah:kpah Louisiana:Fort Polk:kpoe Louisiana:Lake Charles:klch Louisiana:New Orleans:klix Louisiana:Shreveport:kshv Maine:Caribou:kcbw Maine:Portland:kgyx Maryland:Baltimore:klwx Massachusetts:Boston:kbox Michigan:Detroit:kdtx Michigan:Gaylord:kapx Michigan:Grand Rapids:kgrr Michigan:Marquette:kmqt Minnesota:Duluth:kdlh Minnesota:Minneapolis:kmpx Mississippi:Columbus AFB:kgwx Mississippi:Brandon/Jackson:kdgx Missouri:Kansas City:keax Missouri:Springfield:ksgf Missouri:St. Louis:klsx Montana:Billings:kblx Montana:Glasgow:kggw Montana:Great Falls:ktfx Montana:Missoula:kmsx Nebraska:Hastings:kuex Nebraska:North Platte:klnx Nebraska:Omaha:koax Nevada:Elko:klrx Nevada:Las Vegas:kesx Nevada:Reno:krgx New Jersey:Mt. Holly:kdix New Mexico:Albuquerque:kabx New Mexico:Cannon AFB:kfdx New Mexico:Holloman AFB:khdx New York:Albany:kenx New York:Binghamton:kbgm New York:Buffalo:kbuf New York:Montague:ktyx New York:New York City:kokx New York:Upton:kokx North Carolina:Durham:krax North Carolina:Morehead City:kmhx North Carolina:Raleigh:krax North Carolina:Wilmington:kltx North Dakota:Bismarck:kbis North Dakota:Grand Forks:kmvx North Dakota:Minot AFB:kmbx Ohio:Cincinnati:kiln Ohio:Cleveland:kcle Ohio:Dayton:kiln Ohio:Wilmington:kiln Oklahoma:Frederick:kfdr Oklahoma:Oklahoma City:ktlx Oklahoma:Tulsa:kinx Oklahoma:Vance AFB:kvnx Oregon:Medford:kmax Oregon:Pendelton:kpdt Oregon:Portland:krtx Pennsylvania:Philadelphia:kdix Pennsylvania:Pittsburgh:kpbz Pennsylvania:State College:kccx Puerto Rico:Puerto Rico/V.I.:tjua South Carolina:Charleston:kclx South Carolina:Columbia:kcae South Carolina:Greenville:kgsp South Carolina:Spartanburg:kgsp South Carolina:Greer:kgsp South Dakota:Aberdeen:kabr South Dakota:Rapid City:kudx South Dakota:Sioux Falls:kfsd Tennessee:Knoxville:kmrx Tennessee:Memphis:kqna Tennessee:Morristown:kmrx Tennessee:Nashville:kohx Tennessee:Tri Cities:kmrx Texas:Amarillo:kama Texas:Austin:kewx Texas:Brownsville:kbro Texas:Central Texas:kgrk Texas:Corpus Cristi:kcrp Texas:Dallas:kfws Texas:Dyess AFB:kdyx Texas:El Passo:kepz Texas:Fort Worth:kfws Texas:Galveston:khgx Texas:Houston:khgx Texas:Laughlin AFB:kdfx Texas:Lubbock:klbb Texas:Midland/Odessa:kmaf Texas:San Angelo:ksjt Texas:San Antonio:kewx Utah:Cedar City:kicx Utah:Salt Lake City:kmtx Vermont:Burlington:kcxx Virginia:Blacksburg:kfcx Virginia:Norfolk:kakq Virginia:Roanoke:kfcx Virginia:Sterling:klwx Virginia:Wakefield:kakq Washington:Seattle:katx Washington:Spokane:kotx Washington:Tacoma:katx Washington DC:Washington:klwx West Virginia:Charleston:krlx Wisconsin:Green Bay:kgrb Wisconsin:La Crosse:karx Wisconsin:Milwaukee:kmkx Wyoming:Cheyenne:kcys Wyoming:Riverton:kriw

In reply to ztk-weather-radar by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.