- fix: WeatherData asset not displaying properly
- rfe: Weather-Data not only for US-Cities - rfe: WeatherData Asset - Convert to International format
This commit is contained in:
parent
4469301092
commit
2ae31ce34b
8 changed files with 96 additions and 85 deletions
|
|
@ -15,14 +15,13 @@ package WebGUI::Asset::File;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use base 'WebGUI::Asset';
|
||||
use WebGUI::Cache;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Utility;
|
||||
use FileHandle;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset);
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ package WebGUI::Asset::File::ZipArchive;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Asset::File;
|
||||
use base 'WebGUI::Asset::File';
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Utility;
|
||||
|
|
@ -23,7 +23,6 @@ use WebGUI::Utility;
|
|||
use Archive::Tar;
|
||||
use Archive::Zip;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::File);
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
|
|||
|
|
@ -12,25 +12,14 @@ package WebGUI::Asset::Wobject::WeatherData;
|
|||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Portions of the below are originally from Weather::Underground,
|
||||
and are not included in this copyright.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
|
||||
use LWP::UserAgent;
|
||||
use Tie::CPHash;
|
||||
use Tie::IxHash;
|
||||
use JSON;
|
||||
use WebGUI::Cache;
|
||||
use Weather::Com::Simple;
|
||||
use WebGUI::International;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Asset::Wobject;
|
||||
use base 'WebGUI::Asset::Wobject';
|
||||
use WebGUI::Utility;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -46,6 +35,21 @@ sub definition {
|
|||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session, "Asset_WeatherData");
|
||||
my $properties = {
|
||||
partnerId => {
|
||||
fieldType => "text",
|
||||
tab => "properties",
|
||||
defaultValue => undef,
|
||||
hoverHelp => "partnerId help",
|
||||
label => "partnerId",
|
||||
subtext => '<a href="http://www.weather.com/services/xmloap.html">'.$i18n->get("you need a weather.com key").'</a>',
|
||||
},
|
||||
licenseKey => {
|
||||
fieldType => "text",
|
||||
tab => "properties",
|
||||
defaultValue => undef,
|
||||
hoverHelp => "licenseKey help",
|
||||
label => "licenseKey",
|
||||
},
|
||||
templateId =>{
|
||||
fieldType=>"template",
|
||||
tab=>"display",
|
||||
|
|
@ -56,7 +60,7 @@ sub definition {
|
|||
},
|
||||
locations=>{
|
||||
fieldType=>"textarea",
|
||||
defaultValue=>"Grayslake,IL",
|
||||
defaultValue=>"Madison, WI\nToronto, Canada\n53536",
|
||||
tab=>"properties",
|
||||
hoverHelp=>$i18n->get("Your list of default weather locations"),
|
||||
label=>$i18n->get("Default Locations")
|
||||
|
|
@ -75,49 +79,6 @@ sub definition {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _getLocationData ( )
|
||||
|
||||
Accepts a location, and returns a hashref of information about the weather
|
||||
at that location.
|
||||
|
||||
=cut
|
||||
|
||||
sub _getLocationData {
|
||||
my $self = shift;
|
||||
my $location = shift;
|
||||
my $cache = WebGUI::Cache->new($self->session,["weatherLocation",$location]);
|
||||
my $locData = $cache->get;
|
||||
unless ($locData->{cityState}) {
|
||||
my $oldagent;
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->env_proxy;
|
||||
$ua->timeout(10);
|
||||
$oldagent = $ua->agent();
|
||||
$ua->agent($self->session->env->get("HTTP_USER_AGENT")); # Act as a proxy.
|
||||
my $response = $ua->get('http://www.srh.noaa.gov/port/port_zc.php?inputstring='.$location);
|
||||
my $document = $response->content;
|
||||
$document =~ s/\n/ /g;
|
||||
$document =~ s/\s+/ /g;
|
||||
$document =~ m!<div\salign="center">\s(.*?)<br>.*?<br>.*?<br>.*?<br>\s(.*?):\s(.*?) °F<br>!;
|
||||
|
||||
my ($cityState, $sky, $tempF) = ($1, $2, $3);
|
||||
my $iconBasename = $self->_chooseWeatherConditionsIcon($2);
|
||||
|
||||
$locData = {
|
||||
query => $location,
|
||||
cityState => $cityState || $location,
|
||||
sky => $sky || 'N/A',
|
||||
tempF => $tempF || 'N/A',
|
||||
iconUrl => $self->session->url->extras("wobject/WeatherData/".$iconBasename.'.jpg'),
|
||||
iconAlt => $iconBasename,
|
||||
};
|
||||
$cache->set($locData, 60*60) if $locData->{sky} ne 'NULL';
|
||||
}
|
||||
return $locData;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _chooseWeatherConditionsIcon ( currentSkyConditionsEnglish )
|
||||
|
||||
Accepts a string that represents the current sky conditions. Taken
|
||||
|
|
@ -228,22 +189,27 @@ to be displayed within the page style
|
|||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $var = $self->get();
|
||||
#Set some template variables
|
||||
|
||||
#Build list of locations as an array
|
||||
my $defaults = $self->get("locations");
|
||||
#replace any windows newlines
|
||||
$defaults =~ s/\r//gm;
|
||||
my @array = split("\n",$defaults);
|
||||
#trim locations of whitespace
|
||||
my @locs = ();
|
||||
for (my $i = 0; $i < scalar(@array); $i++) {
|
||||
$array[$i] = $self->_trim($array[$i]);
|
||||
push(@locs, $self->_getLocationData($array[$i]));
|
||||
my %var;
|
||||
foreach my $location (split("\n", $self->get("locations"))) {
|
||||
my $weather = Weather::Com::Simple->new({
|
||||
'partner_id' => $self->get("partnerId"),
|
||||
'license' => $self->get("licenseKey"),
|
||||
'place' => $location,
|
||||
'cache' => '/tmp',
|
||||
});
|
||||
foreach my $foundLocation (@{$weather->get_weather}) {
|
||||
push(@{$var{'ourLocations.loop'}}, {
|
||||
query => $location,
|
||||
cityState => $foundLocation->{place} || $location,
|
||||
sky => $foundLocation->{conditions} || 'N/A',
|
||||
tempF => $foundLocation->{temperature_fahrenheit} || 'N/A',
|
||||
tempC => $foundLocation->{temperature_celsius} || 'N/A',
|
||||
iconUrl => $self->session->url->extras("wobject/WeatherData/".$self->_chooseWeatherConditionsIcon($foundLocation->{conditions}).'.jpg'),
|
||||
iconAlt => $foundLocation->{conditions},
|
||||
});
|
||||
}
|
||||
}
|
||||
$var->{'ourLocations.loop'} = \@locs;
|
||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||
return $self->processTemplate(\%var, undef, $self->{_viewTemplate});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,16 @@ our $HELP = {
|
|||
},
|
||||
],
|
||||
fields => [
|
||||
{
|
||||
title => 'partnerId',
|
||||
description => 'partnerId help',
|
||||
namespace => 'Asset_WeatherData',
|
||||
},
|
||||
{
|
||||
title => 'licenseKey',
|
||||
description => 'licenseKey help',
|
||||
namespace => 'Asset_WeatherData',
|
||||
},
|
||||
{
|
||||
title => 'Default Locations',
|
||||
description => 'Your list of default weather locations',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,30 @@
|
|||
package WebGUI::i18n::English::Asset_WeatherData;
|
||||
|
||||
our $I18N = {
|
||||
'you need a weather.com key' => {
|
||||
message => q|Click here to register with weather.com for the free Weather XML Data Feed, which you need to use this asset.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'licenseKey help' => {
|
||||
message => q|You received this key in the email weather.com sent you after registering for the Weather XML Data Feed.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'licenseKey' => {
|
||||
message => q|Weather.com License Key|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'partnerId' => {
|
||||
message => q|Weather.com Partner Id|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'partnerId help' => {
|
||||
message => q|You received this id in the email weather.com sent you after registering for the Weather XML Data Feed.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'Current Weather Conditions Template to use' => {
|
||||
message => q|Current Weather Conditions Template to use|,
|
||||
|
|
@ -13,8 +37,8 @@ our $I18N = {
|
|||
},
|
||||
|
||||
'Your list of default weather locations' => {
|
||||
message => q|Your list of default weather locations, each on its own line. Use City, ST or zipCode.|,
|
||||
lastUpdated => 1133619940,
|
||||
message => q{Your list of default weather locations, each on its own line. Usage: City, ST || Zip Code || City, Country},
|
||||
lastUpdated => 1172425406,
|
||||
},
|
||||
|
||||
'Default Locations' => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue