Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

perlaintdead's scratchpad

by perlaintdead (Scribe)
on May 21, 2011 at 23:48 UTC ( #906105=scratchpad: print w/ replies, xml ) Need Help??

$|=1; use LWP::UserAgent; use HTTP::Headers; use HTTP::Message; use JSON; my $weatherSeeker = LWP::UserAgent->new(); #make Useragent look more human $weatherSeeker->agent('Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like +Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 +Mobile/8A293 Safari/6531.22.7'); #iphone $weatherSeeker->default_header('Accept-Language' => 'en-US,en;q=0.5'); $weatherSeeker->default_header('X-Requested-With' => 'XMLHttpRequest') +; my $randomNum = rand 10000; #idk wft nws is whack #changes this based on your location my $lat = 1; my $lon = 1; while(1){ print scalar localtime, "\n"; my $JSONresp = $weatherSeeker->get('http://mobile.weather.gov/wtf/ +MapClick.php?rand=' . $randomNum . '&lat=' . $lat . '&lon=' . $lon . +'&FcstType=digitalJSON')->decoded_content; print packagereport($JSONresp); $randomNum = rand 10000; sleep aboutAnHour(); print "*" x 50, "\n\n"; } sub packagereport{ my $JSONresponce = shift; my $final = ""; $JSONresponce =~ s/(\x20|\t|\r|\n)//g; my $report = decode_json($JSONresponce); my @desiredStats = ('weather','temperature','windSpeed','cloudAmou +nt','relativeHumidity','windDirectionCardinal',); my $period = ""; if(defined $report->{'Today'}){ $period = 'Today'; }elsif(defined $report->{'Tonight'}){ $period = 'Tonight'; }elsif(defined $report->{'Overnight'}){ $period = 'Overnight'; }else{ print "Period not found. Using Sunday\n"; $period = 'Sunday'; } for my $stat (@desiredStats){ $final .= ucfirst($stat) . ": " . $report->{$period}->{$stat}[ +0] . "\n"; } $final .= "\n"; if($final =~ m/(rain|hail|snow|thunderstorms)/i){ ### alert on awe +some weather $final .= "\a"; } return $final; } sub aboutAnHour(){ #more closly resembles legitimate usage. return( 3600 + int rand 1800 ); }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2015-05-25 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (490 votes), past polls