From f46ddbd809ac83d95895e0d68d7de71bf9f16fa7 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Fri, 10 Feb 2023 11:21:34 -0700 Subject: [PATCH] Fixed fallback code to actually fall back, and a few other reference issues --- weather.sh | 18 +++++++++--------- weatherbug.sh | 10 +++++----- weathergov.sh | 6 +++--- weatherunder.sh | 4 ++-- wttrin.sh | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/weather.sh b/weather.sh index 6ee8c27..48ac49b 100755 --- a/weather.sh +++ b/weather.sh @@ -7,7 +7,7 @@ use JSON; my @path = split("/", $0); pop @path; my $p = join("/", @path); -my $config_file = -e '~/.location.json' ? '~/.location.json' : 'location_example.json'; +my $config_file = -e "$ENV{HOME}/.location.json" ? "$ENV{HOME}/.location.json" : "$p/location_example.json"; # Load up config data open (CONFIG, $config_file) or goto NOCONFIG; @@ -17,12 +17,12 @@ my %config = %{decode_json($raw_config)}; close(CONFIG); NOCONFIG: -my $lat = $config{lat} or scalar(40.48967); -my $lon = $config{lon} or scalar(-111.93882); -my $WB_providerID = $config{WBproviderID} or scalar(23); -my $WB_stationID = $config{WBstationID} or scalar("C3430"); -my $WU_stationID = $config{WUstationID} or scalar("KUTRIVER63"); -my $city = $config{city} or scalar("bluffdale"); +my $lat = ($config{lat} or 40.48967); +my $lon = ($config{lon} or -111.93882); +my $WB_providerID = ($config{WBproviderID} or 23); +my $WB_stationID = ($config{WBstationID} or "C3430"); +my $WU_stationID = ($config{WUstationID} or "KUTRIVER63"); +my $city = ($config{city} or "bluffdale"); sub checksources { my $weather = (`$p/wttrin.sh $city` || `$p/weatherunder.sh $WU_stationID` || `$p/weatherbug.sh $lat $lon $WB_providerID $WB_stationID` || `$p/weathergov.sh $lat $lon`) or print "Not Available\n\n#FF0000" and exit 33; @@ -110,9 +110,9 @@ elsif ($type eq "NA") {$type = "";} elsif ($type =~ /Snow/) {$type = "";} else {$type=$type."...";} -my $loc = substr(($weather[4] or "?????"), 0, 5); +my $loc = substr(($weather[4] or "??????????"), 0, 9); -my $format = '%5.5s - %5.5s  %03dC  %s %03dmph'; +my $format = '%10.10s - %5.5s  %03dC  %s %03dmph'; printf( $format, $loc, $type, $temp, $wdir, $wind); print "\n"; printf( $format, $loc, $type, $temp, $wdir, $wind); diff --git a/weatherbug.sh b/weatherbug.sh index 537f08f..a6980b8 100755 --- a/weatherbug.sh +++ b/weatherbug.sh @@ -4,10 +4,10 @@ use warnings; use JSON; #Have to open the web page and look in developer mode to get this info -my $URL_lat = $ARGV[0] or scalar(40.48967); -my $URL_lng = $ARGV[1] or scalar(-111.93882); -my $URL_ProID = $ARGV[2] or scalar( 23); -my $URL_StatID = $ARGV[3] or scalar("C3430"); +my $URL_lat = ($ARGV[0] or 40.48967); +my $URL_lng = ($ARGV[1] or -111.93882); +my $URL_ProID = ($ARGV[2] or 23); +my $URL_StatID = ($ARGV[3] or "C3430"); my $info = `curl -sm 5 "https://www.weatherbug.com/api/observation?lat=$URL_lat&lng=$URL_lng&providerId=$URL_ProID&stationId=$URL_StatID"` or die "Error"; @@ -18,4 +18,4 @@ my $temp = %{$json}{"Observation"}->{"Temperature"}; my $windS = %{$json}{"Observation"}->{"WindSpeedAvg"}; my $windD = %{$json}{"Observation"}->{"WindDirectionAvg"}; -print "?:".$temp.":".$windS.":".$windD.":".$loc; +print "?:".$temp.":".$windS.":".$windD.":(WB)".$loc; diff --git a/weathergov.sh b/weathergov.sh index 0dd8368..41f4e08 100755 --- a/weathergov.sh +++ b/weathergov.sh @@ -3,8 +3,8 @@ use strict; use warnings; use JSON; -my $URL_lat = $ARGV[0] or scalar(40.4936); -my $URL_lon = $ARGV[1] or scalar(-111.9388); +my $URL_lat = ($ARGV[0] or 40.4936); +my $URL_lon = ($ARGV[1] or -111.9388); 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"; @@ -16,4 +16,4 @@ my $windS = %{$json}{"currentobservation"}->{"Winds"}; my $windD = %{$json}{"currentobservation"}->{"Windd"}; my $desc = %{$json}{"currentobservation"}->{"Weather"}; -print $desc.":".$temp.":".$windS.":".$windD.":".$loc; +print $desc.":".$temp.":".$windS.":".$windD.":(WG)".$loc; diff --git a/weatherunder.sh b/weatherunder.sh index 6530bfe..d6827f0 100755 --- a/weatherunder.sh +++ b/weatherunder.sh @@ -5,7 +5,7 @@ use warnings; use JSON; my $APIKEY = "e1f10a1e78da46f5b10a1e78da96f525"; -my $StationID = $ARGV[0] or scalar("KUTRIVER63"); +my $StationID = ($ARGV[0] or "KUTRIVER63"); my $Units = "m"; # e = imperial, m = metric my $info = `curl -sm 1 "https://api.weather.com/v2/pws/observations/current?apiKey=$APIKEY&stationId=$StationID&numericPrecision=decimal&format=json&units=$Units"` or die "Error"; @@ -17,4 +17,4 @@ 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; +print "?:".$temp.":".$windS.":".$windD.":(WU)".$loc; diff --git a/wttrin.sh b/wttrin.sh index 7a53ba4..65660cd 100755 --- a/wttrin.sh +++ b/wttrin.sh @@ -15,4 +15,4 @@ my $windS = %{$json}{"current_condition"}->[0]->{"windspeedMiles"}; my $windD = %{$json}{"current_condition"}->[0]->{"winddirDegree"}; my $desc = %{$json}{"current_condition"}->[0]->{"weatherDesc"}->[0]->{"value"}; -print $desc.":".$temp.":".$windS.":".$windD.":".$loc; +print $desc.":".$temp.":".$windS.":".$windD.":(WT)".$loc;