Added localized config file with default fallbacks, fixed a few issue, replaced wb api key
This commit is contained in:
parent
6d21607b8c
commit
a9e23843ce
8
location_example.json
Normal file
8
location_example.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"lat":"40.49967",
|
||||
"lon":"-111.9388",
|
||||
"WBproviderID":"23",
|
||||
"WBstationID":"C3430",
|
||||
"WUstationID":"KUTRIVER63",
|
||||
"city":"bluffdale"
|
||||
}
|
19
weather.sh
19
weather.sh
@ -2,13 +2,30 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Math::Trig;
|
||||
use JSON;
|
||||
|
||||
my @path = split("/", $0);
|
||||
pop @path;
|
||||
my $p = join("/", @path);
|
||||
my $config_file = -e '~/.location.json' ? '~/.location.json' : 'location_example.json';
|
||||
|
||||
# Load up config data
|
||||
open (CONFIG, $config_file) or goto NOCONFIG;
|
||||
my $raw_config = "";
|
||||
while (<CONFIG>) { $raw_config .= $_; }
|
||||
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");
|
||||
|
||||
sub checksources {
|
||||
my $weather = (`$p/wttrin.sh` || `$p/weatherunder.sh` || `$p/weatherbug.sh` || `$p/weathergov.sh`) or print "Not Available\n\n#FF0000" and exit 33;
|
||||
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;
|
||||
return $weather;
|
||||
}
|
||||
|
||||
|
@ -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 = 40.48967;
|
||||
my $URL_lng = -111.93882;
|
||||
my $URL_ProID = 23;
|
||||
my $URL_StatID = "C3430";
|
||||
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 $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";
|
||||
|
||||
|
@ -3,8 +3,8 @@ use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
|
||||
my $URL_lat = 40.4936;
|
||||
my $URL_lon = -111.9388;
|
||||
my $URL_lat = $ARGV[0] or scalar(40.4936);
|
||||
my $URL_lon = $ARGV[1] or scalar(-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";
|
||||
|
||||
|
@ -4,11 +4,11 @@ use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
|
||||
my $APIKEY = "6532d6454b8aa370768e63d6ba5a832e";
|
||||
my $StationID = "KUTRIVER63";
|
||||
my $APIKEY = "e1f10a1e78da46f5b10a1e78da96f525";
|
||||
my $StationID = $ARGV[0] or scalar("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 $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";
|
||||
|
||||
my $json = decode_json $info or die "Error";
|
||||
|
||||
|
@ -3,11 +3,13 @@ use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
|
||||
my $info = `curl -sm 5 wttr.in/bluffdale?format=j1` or die "Error";
|
||||
my $city = $ARGV[0] or scalar("bluffdale");
|
||||
|
||||
my $info = `curl -sm 5 wttr.in/$city?format=j1` or die "Error";
|
||||
|
||||
my $json = decode_json $info or die "Error";
|
||||
|
||||
my $loc = %{$json}{"nearest_area"}->[0]->{"areaName"}->{"value"};
|
||||
my $loc = %{$json}{"nearest_area"}->[0]->{"areaName"}->[0]->{"value"};
|
||||
my $temp = %{$json}{"current_condition"}->[0]->{"temp_F"};
|
||||
my $windS = %{$json}{"current_condition"}->[0]->{"windspeedMiles"};
|
||||
my $windD = %{$json}{"current_condition"}->[0]->{"winddirDegree"};
|
||||
|
Loading…
x
Reference in New Issue
Block a user