Fixed fallback code to actually fall back, and a few other reference issues

This commit is contained in:
bluesaxman 2023-02-10 11:21:34 -07:00
parent a9e23843ce
commit f46ddbd809
5 changed files with 20 additions and 20 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;