weatherget/weathergov.sh

20 lines
661 B
Bash
Raw Normal View History

2020-01-21 14:01:04 -07:00
#!/usr/bin/perl -w
use strict;
use warnings;
use JSON;
my $URL_lat = $ARGV[0] or scalar(40.4936);
my $URL_lon = $ARGV[1] or scalar(-111.9388);
2020-01-21 14:01:04 -07:00
2020-01-21 15:10:25 -07:00
my $info = `curl -sm 5 "https://forecast.weather.gov/MapClick.php?lat=$URL_lat&lon=$URL_lon&unit=0&lg=english&FcstType=json"` or die "Error";
2020-01-21 14:01:04 -07:00
my $json = decode_json $info or die "Error";
my $loc = %{$json}{"location"}->{"areaDescription"};
2020-01-21 14:01:04 -07:00
my $temp = %{$json}{"currentobservation"}->{"Temp"};
my $windS = %{$json}{"currentobservation"}->{"Winds"};
my $windD = %{$json}{"currentobservation"}->{"Windd"};
my $desc = %{$json}{"currentobservation"}->{"Weather"};
print $desc.":".$temp.":".$windS.":".$windD.":".$loc;