$|=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','cloudAmount','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 awesome weather $final .= "\a"; } return $final; } sub aboutAnHour(){ #more closly resembles legitimate usage. return( 3600 + int rand 1800 ); }