From 10add91c6183ea5db39e7fbecc70a012784d9cfd Mon Sep 17 00:00:00 2001 From: Robert Unverzagt Date: Wed, 30 Jun 2021 18:31:24 -0700 Subject: [PATCH 1/6] Adding a weather block. Data is pulled from NOAA so only works within the USA. Script uses an agency-specific naming convention which would allow for other agencies to be added in the future. --- weather/README.md | 18 +++++++++ weather/i3blocks.conf | 5 +++ weather/weather_NOAA | 86 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 weather/README.md create mode 100644 weather/i3blocks.conf create mode 100755 weather/weather_NOAA diff --git a/weather/README.md b/weather/README.md new file mode 100644 index 0000000..4d1a041 --- /dev/null +++ b/weather/README.md @@ -0,0 +1,18 @@ +# weather + +Retrieve short term forecast from NOAA. +Since the forecast is from NOAA, this script only works within the USA. +# Dependencies + +* `curl` +* `JSON` perl module, can be found in CPAN + +# Usage + +``` ini +[weather] +command=./weather/weather_NOAA +#LAT=45.52 +#LON=-122.6819 +interval=600 +``` diff --git a/weather/i3blocks.conf b/weather/i3blocks.conf new file mode 100644 index 0000000..6716e3d --- /dev/null +++ b/weather/i3blocks.conf @@ -0,0 +1,5 @@ +[weather] +command=$SCRIPT_DIR/weather/weather_NOAA +#LAT=45.52 +#LON=-122.6819 +interval=600 diff --git a/weather/weather_NOAA b/weather/weather_NOAA new file mode 100755 index 0000000..5c36dda --- /dev/null +++ b/weather/weather_NOAA @@ -0,0 +1,86 @@ +#!/usr/bin/env perl +# +# Copyright 2021 Robert Unverzagt +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use strict; +use warnings; +use JSON; +use Data::Dumper; +use Getopt::Long; + +# Default option values (default location is Portland, OR) +my $lat = $ENV{LAT} || "45.52"; +my $lon = $ENV{LON} || "-122.70"; + +sub help { + print "Usage: weather_NOAA [-s -x -y ]\n"; + print "If specifying a location, all three options are required\n"; + print "This info can be found at https://weather.gov\n"; + exit 0; +} + +GetOptions( "help|h" => \&help, + "lat=s" => \$lat, + "lon=s" => \$lon, +); + +# Use CURL to retrieve station ID and gridpoint +my $json; +{ + open( my $fh, 'curl -s https:\/\/api.weather.gov\/points\/'.$lat.','.$lon.' |') or die; + local $/; + $json = <$fh>; + close $fh; +} + + +# Decode the json data into a perl native datatype, and extract the data we need +my $decoded = decode_json($json); + +# Detect error +if ($decoded->{"status"}) +{ + print "ERROR: ".$decoded->{'title'}."\n"; + print $decoded->{'detail'}."\n"; + die; +} + +my $stationID = $decoded->{'properties'}->{'gridId'}; +my $Xcoord = $decoded->{'properties'}->{'gridX'}; +my $Ycoord = $decoded->{'properties'}->{'gridY'}; + +# Use CURL to retrieve the forecast from NOAA +{ + open( my $fh, 'curl -s https:\/\/api.weather.gov\/gridpoints\/'.$stationID.'\/'.$Xcoord.','.$Ycoord.'\/forecast\/hourly |') or die; + local $/; + $json = <$fh>; + close $fh; +} + +$decoded = decode_json($json); + +if ($decoded->{"status"}) +{ + print "ERROR: ".$decoded->{'title'}."\n"; + print $decoded->{'detail'}."\n"; + die; +} + +# Extract just the forecast for the next hour +my $forecast = $decoded->{'properties'}->{'periods'}->[0]; + +# Use this forecast data to construct the output string +print $forecast->{'temperature'}."°".$forecast->{'temperatureUnit'}." ".$forecast->{'shortForecast'}."\n"; From e5806bd1d2579fcff6eb781214e98eba587b76a6 Mon Sep 17 00:00:00 2001 From: Robert Unverzagt Date: Wed, 30 Jun 2021 18:41:44 -0700 Subject: [PATCH 2/6] Correct help message of weather_NOAA script --- weather/weather_NOAA | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/weather/weather_NOAA b/weather/weather_NOAA index 5c36dda..e0ba4eb 100755 --- a/weather/weather_NOAA +++ b/weather/weather_NOAA @@ -26,9 +26,10 @@ my $lat = $ENV{LAT} || "45.52"; my $lon = $ENV{LON} || "-122.70"; sub help { - print "Usage: weather_NOAA [-s -x -y ]\n"; - print "If specifying a location, all three options are required\n"; - print "This info can be found at https://weather.gov\n"; + print "Usage: weather_NOAA [-lat ] [-lon ]\n"; + print "-lat : the latitude coordinate of your location\n"; + print "-lon : the longitude coordinate of your location\n\n"; + print "NOTE: Only works in areas where NOAA publishes forecasts (namely the USA)\n"; exit 0; } From 19cbccc6edd33c6f480097bcfdf20c8962f38b40 Mon Sep 17 00:00:00 2001 From: Robert Unverzagt Date: Wed, 30 Jun 2021 18:53:42 -0700 Subject: [PATCH 3/6] weather_NOAA: fix blocket naming convention. add screenshot --- weather_NOAA/README.md | 18 +++++++ weather_NOAA/i3blocks.conf | 5 ++ weather_NOAA/weather_NOAA | 87 ++++++++++++++++++++++++++++++++++ weather_NOAA/weather_NOAA.png | Bin 0 -> 10257 bytes 4 files changed, 110 insertions(+) create mode 100644 weather_NOAA/README.md create mode 100644 weather_NOAA/i3blocks.conf create mode 100755 weather_NOAA/weather_NOAA create mode 100644 weather_NOAA/weather_NOAA.png diff --git a/weather_NOAA/README.md b/weather_NOAA/README.md new file mode 100644 index 0000000..4d1a041 --- /dev/null +++ b/weather_NOAA/README.md @@ -0,0 +1,18 @@ +# weather + +Retrieve short term forecast from NOAA. +Since the forecast is from NOAA, this script only works within the USA. +# Dependencies + +* `curl` +* `JSON` perl module, can be found in CPAN + +# Usage + +``` ini +[weather] +command=./weather/weather_NOAA +#LAT=45.52 +#LON=-122.6819 +interval=600 +``` diff --git a/weather_NOAA/i3blocks.conf b/weather_NOAA/i3blocks.conf new file mode 100644 index 0000000..6716e3d --- /dev/null +++ b/weather_NOAA/i3blocks.conf @@ -0,0 +1,5 @@ +[weather] +command=$SCRIPT_DIR/weather/weather_NOAA +#LAT=45.52 +#LON=-122.6819 +interval=600 diff --git a/weather_NOAA/weather_NOAA b/weather_NOAA/weather_NOAA new file mode 100755 index 0000000..e0ba4eb --- /dev/null +++ b/weather_NOAA/weather_NOAA @@ -0,0 +1,87 @@ +#!/usr/bin/env perl +# +# Copyright 2021 Robert Unverzagt +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use strict; +use warnings; +use JSON; +use Data::Dumper; +use Getopt::Long; + +# Default option values (default location is Portland, OR) +my $lat = $ENV{LAT} || "45.52"; +my $lon = $ENV{LON} || "-122.70"; + +sub help { + print "Usage: weather_NOAA [-lat ] [-lon ]\n"; + print "-lat : the latitude coordinate of your location\n"; + print "-lon : the longitude coordinate of your location\n\n"; + print "NOTE: Only works in areas where NOAA publishes forecasts (namely the USA)\n"; + exit 0; +} + +GetOptions( "help|h" => \&help, + "lat=s" => \$lat, + "lon=s" => \$lon, +); + +# Use CURL to retrieve station ID and gridpoint +my $json; +{ + open( my $fh, 'curl -s https:\/\/api.weather.gov\/points\/'.$lat.','.$lon.' |') or die; + local $/; + $json = <$fh>; + close $fh; +} + + +# Decode the json data into a perl native datatype, and extract the data we need +my $decoded = decode_json($json); + +# Detect error +if ($decoded->{"status"}) +{ + print "ERROR: ".$decoded->{'title'}."\n"; + print $decoded->{'detail'}."\n"; + die; +} + +my $stationID = $decoded->{'properties'}->{'gridId'}; +my $Xcoord = $decoded->{'properties'}->{'gridX'}; +my $Ycoord = $decoded->{'properties'}->{'gridY'}; + +# Use CURL to retrieve the forecast from NOAA +{ + open( my $fh, 'curl -s https:\/\/api.weather.gov\/gridpoints\/'.$stationID.'\/'.$Xcoord.','.$Ycoord.'\/forecast\/hourly |') or die; + local $/; + $json = <$fh>; + close $fh; +} + +$decoded = decode_json($json); + +if ($decoded->{"status"}) +{ + print "ERROR: ".$decoded->{'title'}."\n"; + print $decoded->{'detail'}."\n"; + die; +} + +# Extract just the forecast for the next hour +my $forecast = $decoded->{'properties'}->{'periods'}->[0]; + +# Use this forecast data to construct the output string +print $forecast->{'temperature'}."°".$forecast->{'temperatureUnit'}." ".$forecast->{'shortForecast'}."\n"; diff --git a/weather_NOAA/weather_NOAA.png b/weather_NOAA/weather_NOAA.png new file mode 100644 index 0000000000000000000000000000000000000000..5ba7ee6dc32338b0fb2f952d5170bab23d5f1dbe GIT binary patch literal 10257 zcmeHtXH-*L&~^Zo4ubTeAyk1t=rweZF4C16NPy4@p?46e(ov8i2q+*OlqyA~_ujjJ zbOaQnzQNnq_x`zSeeb`Utdn!j-ZRghd1hvxz0XR7mgYTT0y+W!06?swte}lKhhPpm zyc?L`q{H290Dz>-Th|b+4f6mxqnxae_6Q)_%NYSgcp|L;0MDu7R67()E%D>a0}3hZ zd0>qE9@!%O@$rS$?2zh<^6|yl^|+B~6Gd_vkiY}_zNQPWPtwN*xzSo_(Ip@5UFa3R zV0TjTJx}Z3rPw?;{VCFQT7P(c5Vv|7)pO5(@bu&0{CI$GrWCd3d1`~585P~;d8pr| z+@{a@H_Pm^6P+`K3;!nSp(8ogrbgx6>#L`^CSktBEq$B2rxylv$M_d-V|LpwR+>V$ zw%epw*L1Wa&ie8iNwm(`L;1aif0{&^rF1R$Eel+plNGY>i+DwvX;S*@uN=(A7ABpY zzDl~N1MRgO!GH8OHJwYoyYsS%n&^IH(@w+O?*38#^f7ajS>l%T(GJ-TwDhahc5YQu z$O+yzul7)-u5MSOHP$o1x$XmPQ|7=q#ZC|7LC@mcyE@O(Y^RW~)A|lP@>)_*U_;@PD4t=!anQos^{v_>`iwS z3kBCf{0fK|{tcTPQd(vrMx9Ekj&h{IV0NKv#X5YYb2gE1waUJ=P-v4)SlxkVp>o6a zE$>5SZWGrv6Jg2n(`V54J6=Ors&6vgPvQk)GQEPPz}0i^r^yl}b3Y%x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f0-91tF#mmsBzpZCgbuCq^r~N6*?v9t#->c}XamtH zDPnzM`2FL^NYahG2RN6k;AxF2r%Q1vD(FPHLu}+^XsDtBgVd9Qt<)luv#1WZ;>7gyzN(Q9i%W#A!T25pwXRx&N=P+! z^Ox$SnyN!G6;4jhNvfK(I6qj=5gHLPPq#Byd(X;BGipgiU0F7pquqUE9s&{ce60ZZ zVpj7xFvxFkZ0z;>_wN;@y1KcvIFldyyM})iupT|-(KLK#spMGBOA0Iw(~ZHKl513JMtXX!t-;-xnPy>sh0AulI4xFxcxSdA#7{{^ zMb)xx6go0KZaIfN>EMpw;PS~0G9{e3X@eg}Ni|s7L^=FggGto$rLD2DGEIvQ_P2d^ zW@hH7h?r%s?RN(F(&#VunLdEccB{JQszb5$UIafw+c-d(#Vc<0Y0B7SYS6yDsM^{l<+W zht+o;#1Gm}HIP94pg*<=eXO?DSR>M7$OXnnBTPSlMLmQwF^{~So~fMD()$A?rD;`! zbBuBeKb|HfcdDpp;sycKx^Ke~D+vkdG3xGNb#>xw8Yj2}UScNo?yzUWRn!vbM~eqy zJGXgid};#634? z&UjU?oHwbl1G>$u^P)GQmCM=V<)^B3otl8A$LHCLTj!hD!Y<8gg>vQPjoenP~!;nL@|N=$`BatA!;ifP(t@LcKfl0d&p6 z?ug|2_2-6la7we?>A`(DH}gxf7yWal*qC*bs+ASV1wGD1^+oBGcVernGc!xzs+FDHTmx~7mz0E5-Vo0L85D}Q%zN~t$ye&d3t1eE-mIV} fM0Aokmp6{oMWlz_AZD1QBtS(`Q=vr8JotYAX`B2M literal 0 HcmV?d00001 From 2b83b910ab679a7bec59e27c301ef570dc411286 Mon Sep 17 00:00:00 2001 From: Robert Unverzagt Date: Wed, 30 Jun 2021 18:57:35 -0700 Subject: [PATCH 4/6] weather_NOAA: correct script path in README and i3blocks.conf. Properly remove old directory name --- weather/README.md | 18 -------- weather/i3blocks.conf | 5 --- weather/weather_NOAA | 87 -------------------------------------- weather_NOAA/README.md | 6 +-- weather_NOAA/i3blocks.conf | 2 +- 5 files changed, 4 insertions(+), 114 deletions(-) delete mode 100644 weather/README.md delete mode 100644 weather/i3blocks.conf delete mode 100755 weather/weather_NOAA diff --git a/weather/README.md b/weather/README.md deleted file mode 100644 index 4d1a041..0000000 --- a/weather/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# weather - -Retrieve short term forecast from NOAA. -Since the forecast is from NOAA, this script only works within the USA. -# Dependencies - -* `curl` -* `JSON` perl module, can be found in CPAN - -# Usage - -``` ini -[weather] -command=./weather/weather_NOAA -#LAT=45.52 -#LON=-122.6819 -interval=600 -``` diff --git a/weather/i3blocks.conf b/weather/i3blocks.conf deleted file mode 100644 index 6716e3d..0000000 --- a/weather/i3blocks.conf +++ /dev/null @@ -1,5 +0,0 @@ -[weather] -command=$SCRIPT_DIR/weather/weather_NOAA -#LAT=45.52 -#LON=-122.6819 -interval=600 diff --git a/weather/weather_NOAA b/weather/weather_NOAA deleted file mode 100755 index e0ba4eb..0000000 --- a/weather/weather_NOAA +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright 2021 Robert Unverzagt -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -use strict; -use warnings; -use JSON; -use Data::Dumper; -use Getopt::Long; - -# Default option values (default location is Portland, OR) -my $lat = $ENV{LAT} || "45.52"; -my $lon = $ENV{LON} || "-122.70"; - -sub help { - print "Usage: weather_NOAA [-lat ] [-lon ]\n"; - print "-lat : the latitude coordinate of your location\n"; - print "-lon : the longitude coordinate of your location\n\n"; - print "NOTE: Only works in areas where NOAA publishes forecasts (namely the USA)\n"; - exit 0; -} - -GetOptions( "help|h" => \&help, - "lat=s" => \$lat, - "lon=s" => \$lon, -); - -# Use CURL to retrieve station ID and gridpoint -my $json; -{ - open( my $fh, 'curl -s https:\/\/api.weather.gov\/points\/'.$lat.','.$lon.' |') or die; - local $/; - $json = <$fh>; - close $fh; -} - - -# Decode the json data into a perl native datatype, and extract the data we need -my $decoded = decode_json($json); - -# Detect error -if ($decoded->{"status"}) -{ - print "ERROR: ".$decoded->{'title'}."\n"; - print $decoded->{'detail'}."\n"; - die; -} - -my $stationID = $decoded->{'properties'}->{'gridId'}; -my $Xcoord = $decoded->{'properties'}->{'gridX'}; -my $Ycoord = $decoded->{'properties'}->{'gridY'}; - -# Use CURL to retrieve the forecast from NOAA -{ - open( my $fh, 'curl -s https:\/\/api.weather.gov\/gridpoints\/'.$stationID.'\/'.$Xcoord.','.$Ycoord.'\/forecast\/hourly |') or die; - local $/; - $json = <$fh>; - close $fh; -} - -$decoded = decode_json($json); - -if ($decoded->{"status"}) -{ - print "ERROR: ".$decoded->{'title'}."\n"; - print $decoded->{'detail'}."\n"; - die; -} - -# Extract just the forecast for the next hour -my $forecast = $decoded->{'properties'}->{'periods'}->[0]; - -# Use this forecast data to construct the output string -print $forecast->{'temperature'}."°".$forecast->{'temperatureUnit'}." ".$forecast->{'shortForecast'}."\n"; diff --git a/weather_NOAA/README.md b/weather_NOAA/README.md index 4d1a041..2df512d 100644 --- a/weather_NOAA/README.md +++ b/weather_NOAA/README.md @@ -1,4 +1,4 @@ -# weather +# weather_NOAA Retrieve short term forecast from NOAA. Since the forecast is from NOAA, this script only works within the USA. @@ -10,8 +10,8 @@ Since the forecast is from NOAA, this script only works within the USA. # Usage ``` ini -[weather] -command=./weather/weather_NOAA +[weather_NOAA] +command=./weather_NOAA/weather_NOAA #LAT=45.52 #LON=-122.6819 interval=600 diff --git a/weather_NOAA/i3blocks.conf b/weather_NOAA/i3blocks.conf index 6716e3d..32f1d25 100644 --- a/weather_NOAA/i3blocks.conf +++ b/weather_NOAA/i3blocks.conf @@ -1,5 +1,5 @@ [weather] -command=$SCRIPT_DIR/weather/weather_NOAA +command=$SCRIPT_DIR/weather_NOAA/weather_NOAA #LAT=45.52 #LON=-122.6819 interval=600 From 73be8a83fad91988ccb4f4932ea275c88e1754ac Mon Sep 17 00:00:00 2001 From: Robert Unverzagt Date: Wed, 30 Jun 2021 18:59:15 -0700 Subject: [PATCH 5/6] weather_NOAA: correct blocket name in i3blocks.conf --- weather_NOAA/i3blocks.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weather_NOAA/i3blocks.conf b/weather_NOAA/i3blocks.conf index 32f1d25..fa3f3f4 100644 --- a/weather_NOAA/i3blocks.conf +++ b/weather_NOAA/i3blocks.conf @@ -1,4 +1,4 @@ -[weather] +[weather_NOAA] command=$SCRIPT_DIR/weather_NOAA/weather_NOAA #LAT=45.52 #LON=-122.6819 From c03dc2883c6ca86882d84ae2fab5106661a7d21f Mon Sep 17 00:00:00 2001 From: Robert Unverzagt Date: Wed, 30 Jun 2021 19:01:27 -0700 Subject: [PATCH 6/6] weather_NOAA: fix script path in README.md. Add screenshot in README.md --- weather_NOAA/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/weather_NOAA/README.md b/weather_NOAA/README.md index 2df512d..bfc3be8 100644 --- a/weather_NOAA/README.md +++ b/weather_NOAA/README.md @@ -2,6 +2,9 @@ Retrieve short term forecast from NOAA. Since the forecast is from NOAA, this script only works within the USA. + +![](weather_NOAA.png) + # Dependencies * `curl` @@ -11,7 +14,7 @@ Since the forecast is from NOAA, this script only works within the USA. ``` ini [weather_NOAA] -command=./weather_NOAA/weather_NOAA +command=$SCRIPT_DIR/weather_NOAA/weather_NOAA #LAT=45.52 #LON=-122.6819 interval=600