From 19487f49014021b9f46261e816f1ad952b0a6ad4 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Wed, 22 Jul 2020 10:29:32 -0600 Subject: [PATCH] added Weather Underground/Weather.com API script to sources --- weather.sh | 2 +- weatherunder.sh | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 weatherunder.sh diff --git a/weather.sh b/weather.sh index 0c08ffc..b160158 100755 --- a/weather.sh +++ b/weather.sh @@ -8,7 +8,7 @@ pop @path; my $p = join("/", @path); sub checksources { - my $weather = (`$p/wttrin.sh` || `$p/weatherbug.sh` || `$p/weathergov.sh`) or print "Not Available\n\n#FF0000" and exit 33; + my $weather = (`$p/wttrin.sh` || `$p/weatherunder.sh` || `$p/weatherbug.sh` || `$p/weathergov.sh`) or print "Not Available\n\n#FF0000" and exit 33; return $weather; } diff --git a/weatherunder.sh b/weatherunder.sh new file mode 100755 index 0000000..0d01d6e --- /dev/null +++ b/weatherunder.sh @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; + +my $APIKEY = "6532d6454b8aa370768e63d6ba5a832e"; +my $StationID = "KUTRIVER63"; +my $Units = "m"; # e = imperial, m = metric + +my $info = `curl -sm "https://api.weather.com/v2/pws/observations/current?apiKey=$APIKEY&stationId=$StationID&numericPrecision=decimal&format=json&units=$Units"` or die "Error"; + +my $json = decode_json $info or die "Error"; + +my $loc = %{$json}{"observations"}->[0]->{"stationID"}; +my $temp = %{$json}{"observations"}->[0]->{"metric"}->{"temp"}; +my $windS = %{$json}{"observations"}->[0]->{"metric"}->{"windSpeed"}; +my $windD = %{$json}{"observations"}->[0]->{"winddir"}; + +print "?:".$temp.":".$windS.":".$windD.":".$loc;