Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New scheduling code, WeatherNOAA fixes, and documentation updates. #627

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 57 additions & 61 deletions bin/get_weather
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Latest version:
# http://misterhouse.net/mh/bin
# Change log:
# - 08/17/16 Updated to fix for changes in "nifty GEO::Weather module"
# - 01/20/99 Created. Replaces filter_weather with the nifty Geo::Weather module
# - The rest of the change log is at the bottom of this file.
#
Expand All @@ -21,31 +22,23 @@

use strict;

my ( $Pgm_Path, $Pgm_Name );

my ($Pgm_Path, $Pgm_Name);
BEGIN {
( $Pgm_Path, $Pgm_Name ) = $0 =~ /(.*)[\\\/](.+)\.?/;
($Pgm_Path, $Pgm_Name) = $0 =~ /(.*)[\\\/](.+)\.?/;
($Pgm_Name) = $0 =~ /([^.]+)/, $Pgm_Path = '.' unless $Pgm_Name;
}

my ($Version) =
q$Revision$ =~ /: (\S+)/; # Note: revision number is auto-updated by cvs
my ($Version) = q$Revision: 1.12 $ =~ /: (\S+)/; # Note: revision number is auto-updated by cvs

#print "Command: $Pgm_Name @ARGV\n";
#print "Version: $Version\n";

use Getopt::Long;
my %parms;
if (
!&GetOptions(
\%parms, "h", "help", "v", "city:s", "zone:s",
"state:s", "data=s", "no_log"
)
or @ARGV
or ( $parms{h} or $parms{help} )
)
{
print <<eof;
if (!&GetOptions(\%parms, "h", "help", "v", "city:s", "zone:s", "state:s",
"data=s", "no_log") or @ARGV or
($parms{h} or $parms{help})) {
print<<eof;

$Pgm_Name gets weather info

Expand All @@ -67,99 +60,102 @@ Usage:
into the data_dir/web directory

Example:
$Pgm_Name -city Rochester -state MN
$Pgm_Name -city Rochester -state MN -zone MPX

eof
exit;
}
}

my ( $conditions, $forecast, %data );
my ($conditions, $forecast, %data);
my %config_parms;

$parms{city} = 'Rochester' unless $parms{city};
$parms{zone} = $parms{city} unless $parms{zone};
#RICK 160817
#$parms{zone} = $parms{city} unless $parms{zone};
$parms{zone} = 'MPX' unless $parms{zone};
$parms{state} = 'MN' unless $parms{state};
$parms{data} = 'all' unless $parms{data};
$data{conditions}++ if $parms{data} eq 'all' or $parms{data} eq 'conditions';
$data{forecast}++ if $parms{data} eq 'all' or $parms{data} eq 'forecast';

use vars '$opt_v';
$opt_v++ if $parms{v}; # Geo::Weather looks at this
$opt_v++ if $parms{v}; # Geo::Weather looks at this

my $caller = caller;
my $return_flag = ( $caller and $caller ne 'main' ) ? 1 : 0;
my $return_flag = ($caller and $caller ne 'main') ? 1 : 0;

#use my_lib "$Pgm_Path/../lib/site"; # See note in lib/mh_perl2exe.pl for lib -> my_lib explaination
BEGIN {
eval "use lib '$Pgm_Path/../lib', '$Pgm_Path/../lib/site'";
} # Use BEGIN eval to keep perl2exe happy
BEGIN { eval "use lib '$Pgm_Path/../lib', '$Pgm_Path/../lib/site'" } # Use BEGIN eval to keep perl2exe happy

require 'handy_utilities.pl'; # For read_mh_opts funcion
&main::read_mh_opts( \%config_parms, $Pgm_Path );
require 'handy_utilities.pl'; # For read_mh_opts funcion
&main::read_mh_opts(\%config_parms, $Pgm_Path);

use Geo::WeatherNOAA;

$Geo::WeatherNOAA::proxy_from_env = 1;

if ( $data{conditions} ) {
print "\nGetting the current weather for $parms{city}, $parms{state}\n";
$conditions =
print_current( $parms{city}, $parms{state}, undef, undef, undef, 1 );
if ($data{conditions}) {
# Rick 160816
#print "\nGetting the current weather for $parms{city}, $parms{state}\n";
print "\nGetting the current weather for $parms{city}, $parms{state}, $parms{zone}\n";
#$conditions = print_current($parms{city}, $parms{state},undef,undef,undef,1);
$conditions = print_current($parms{city}, $parms{zone},undef,undef,undef,1);
# End Rick 160816
$conditions =~ s/&deg;F/ degrees /;
$conditions =~ s/ in\./ inches. /g;
}

if ( $data{forecast} ) {
print "Getting the forecast for $parms{zone}, $parms{state}\n";
$forecast =
print_forecast( $parms{zone}, $parms{state}, undef, undef, undef, 1 );
$forecast =~ s/Geo::WeatherNOAA.pm .+\n//; # Drop geo version
#$forecast =~ s/\.\.\./\. /g;
if ($data{forecast}) {
# RICK 160817
#print "Getting the forecast for $parms{zone}, $parms{state}\n";
print "Getting the forecast for $parms{city}, $parms{state}, $parms{zone}\n";
#$forecast = print_forecast($parms{zone}, $parms{state},undef,undef,undef,1);
$forecast = print_forecast($parms{city}, $parms{zone},undef,undef,undef,1);

$forecast =~ s/Geo::WeatherNOAA.pm .+\n//; # Drop geo version
#$forecast =~ s/\.\.\./\. /g;
$forecast =~ s/(\()(EDT|EST|CDT|CST|MDT|MST|PDT|PST)(\) *)//g;
}

unless ( $parms{no_log} ) {
file_write( "$config_parms{data_dir}/web/weather_conditions.txt",
$conditions )
if $data{conditions};
file_write( "$config_parms{data_dir}/web/weather_forecast.txt", $forecast )
if $data{forecast};

# Hmmm, this fails from a mh run command :(
# system("\\mh\\bin\\house.bat show internet weather data");
# system("\\mh\\bin\\speak hi");
# sleep 3;
unless ($parms{no_log}) {
file_write("$config_parms{data_dir}/web/weather_conditions.txt", $conditions) if $data{conditions};
file_write("$config_parms{data_dir}/web/weather_forecast.txt", $forecast) if $data{forecast};
# Hmmm, this fails from a mh run command :(
# system("\\mh\\bin\\house.bat show internet weather data");
# system("\\mh\\bin\\speak hi");
# sleep 3;
}

if ($return_flag) {

# Dang ... a 'do pgm' can only return a scalar, not a list :(
if ( $data{conditions} ) {
# Dang ... a 'do pgm' can only return a scalar, not a list :(
if ($data{conditions}) {
return $conditions;
}
else {
return $forecast;
}
}
else {
if ( $data{conditions} ) {
print "\nCurrent conditions: $conditions\n";
if ($data{conditions}) {
#print "\nCurrent conditions: $conditions\n";
}
if ( $data{forecast} ) {
print "\nThe forecast is $forecast\n\n";

# print "The extended forecast is $forecast{EXTENDED}\n\n";
# print "This information was updated $forecast{Date} and covers $forecast{Coverage}\n\n";
if ($data{forecast}) {
#print "\nThe forecast is $forecast\n\n";
# print "The extended forecast is $forecast{EXTENDED}\n\n";
# print "This information was updated $forecast{Date} and covers $forecast{Coverage}\n\n";
}
}

# WeatherNOAA methods:
# get_currentWX
# get_currentWX_html
# get_forecast
# print_forecast
# get_currentWX
# get_currentWX_html
# get_forecast
# print_forecast

# $Log: get_weather,v $
# Revision 1.13 2016/08/17 23:05:00 rick steeves
# updated for changes in GEO::WeatherNOAA
#
# Revision 1.12 2005/01/23 23:21:18 winter
# *** empty log message ***
#
Expand Down
Loading