initial commit for weatherget
This commit is contained in:
commit
9160e701b8
91
weather.sh
Executable file
91
weather.sh
Executable file
@ -0,0 +1,91 @@
|
||||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use warnings;
|
||||
use Math::Trig;
|
||||
|
||||
sub checksources {
|
||||
return `./wttrin.sh` or `./weatherbug.sh` or `./weathergov.sh` or print "Not Available\n\n#FF0000" and exit 33;
|
||||
}
|
||||
|
||||
sub wavegen {
|
||||
my $x = shift;
|
||||
my $period = shift;
|
||||
my $phaseshift = shift;
|
||||
my $magnitude = shift;
|
||||
my $y_adjust = shift;
|
||||
return sin($x/($period/pi)+$phaseshift)*$magnitude+$y_adjust;
|
||||
}
|
||||
|
||||
sub hexcolor {
|
||||
my ($temp,$cold,$hot,$rwave,$gwave,$bwave) = @_;
|
||||
my $temp_gauge = ($temp - $cold)/($hot - $cold)*100;
|
||||
|
||||
my $r = (100 * sin($temp_gauge / 10)) + ($temp_gauge - 30) * 2;
|
||||
my $g = ($temp_gauge - 50) * ($temp_gauge - 75) * (0 - 1) / 10 + 100;
|
||||
my $b = ($temp_gauge - 25) * ($temp_gauge - 25) * (0 - 1) / 5 + 100;
|
||||
|
||||
$r *= 2;
|
||||
$g *= 2;
|
||||
$b *= 2;
|
||||
|
||||
#brightness
|
||||
my $brightness = 270; #out of a max of 768 (white)
|
||||
|
||||
#sanitize
|
||||
$r = $r > 0 ? $r : 0;
|
||||
$g = $g > 0 ? $g : 0;
|
||||
$b = $b > 0 ? $b : 0;
|
||||
$r = $r < 255 ? $r : 255;
|
||||
$g = $g < 255 ? $g : 255;
|
||||
$b = $b < 255 ? $b : 255;
|
||||
|
||||
if ($r+$g+$b < $brightness) {
|
||||
$brightness -= ($r+$g+$b);
|
||||
$r += ($brightness/3);
|
||||
$g += ($brightness/3);
|
||||
$b += ($brightness/3);
|
||||
}
|
||||
|
||||
if ($rwave) { $r = $rwave }
|
||||
if ($gwave) { $g = $gwave }
|
||||
if ($bwave) { $b = $bwave }
|
||||
|
||||
my $CR = unpack("H2",pack("I",$r));
|
||||
my $CG = unpack("H2",pack("I",$g));
|
||||
my $CB = unpack("H2",pack("I",$b));
|
||||
|
||||
return "#".$CR.$CG.$CB;
|
||||
}
|
||||
|
||||
sub getdir {
|
||||
my $degree = shift;
|
||||
if ($degree <= 22 ) { return "↑";}
|
||||
if ($degree <= 67 ) { return "↗";}
|
||||
if ($degree <= 112 ) { return "→";}
|
||||
if ($degree <= 157 ) { return "↘";}
|
||||
if ($degree <= 202 ) { return "↓";}
|
||||
if ($degree <= 247 ) { return "↙";}
|
||||
if ($degree <= 292 ) { return "←";}
|
||||
if ($degree <= 337 ) { return "↖";}
|
||||
return "↑";
|
||||
}
|
||||
|
||||
my @weather = split(":",checksources) or print "Not Available\n\n#FF0000" and exit 33;
|
||||
|
||||
my $type = $weather[0];
|
||||
my $temp = sprintf("%.0f", ($weather[1] - 32) * (5/9) ); #converts from F to C
|
||||
my $wind = $weather[2];
|
||||
my $wdir = getdir($weather[3]);
|
||||
|
||||
my $color = hexcolor($temp,-17,42);
|
||||
|
||||
if($type =~ /Rain/) {$type = "";}
|
||||
elsif ($type =~ /Overcast/) {$type = "";}
|
||||
elsif ($type =~ /cloud/) {$type = "";}
|
||||
elsif ($type =~ /Clear/) {$type = "";}
|
||||
elsif ($type =~ /Sun/) {$type = "";}
|
||||
elsif ($type =~ /Snow/) {$type = "";}
|
||||
else {$type=$type."...";}
|
||||
|
||||
print $type." ".$temp." ".$wdir." ".$wind."mph\n\n";
|
||||
print $color."\n";
|
20
weatherbug.sh
Executable file
20
weatherbug.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#! /usr/bin/perl -w
|
||||
use strict;
|
||||
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 $info = `curl https://www.weatherbug.com/api/observation?lat=$URL_lat&lng=$URL_lng&providerId=$URL_ProID&stationId=$URL_StatID` or die "Error";
|
||||
|
||||
my $json = decode_json $info or die "Error";
|
||||
|
||||
my $temp = %{$json}{"Observation"}->{"Temperature"};
|
||||
my $windS = %{$json}{"Observation"}->{"WindSpeedAvg"};
|
||||
my $windD = %{$json}{"Observation"}->{"WindDirectionAvg"};
|
||||
|
||||
print "Unknown:".$temp.":".$windS.":".$windD;
|
18
weathergov.sh
Executable file
18
weathergov.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
|
||||
my $URL_lat = 40.4936;
|
||||
my $URL_lon = -111.9388;
|
||||
|
||||
my $info = `curl "https://forecast.weather.gov/MapClick.php?lat=$URL_lat&lon=$URL_lon&unit=0&lg=english&FcstType=json"` or die "Error";
|
||||
|
||||
my $json = decode_json $info or die "Error";
|
||||
|
||||
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;
|
15
wttrin.sh
Executable file
15
wttrin.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#! /usr/bin/perl -w
|
||||
use strict;
|
||||
use warnings;
|
||||
use JSON;
|
||||
|
||||
my $info = `curl wttr.in/bluffdale?format=j1` or die "Error";
|
||||
|
||||
my $json = decode_json $info or die "Error";
|
||||
|
||||
my $temp = %{$json}{"current_condition"}->[0]->{"temp_F"};
|
||||
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;
|
Loading…
x
Reference in New Issue
Block a user