- 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
|
|
@ -1,5 +1,8 @@
|
||||||
7.3.11
|
7.3.11
|
||||||
- Added an option for enabling coverage tests to testCodebase.pl.
|
- Added an option for enabling coverage tests to testCodebase.pl.
|
||||||
|
- fix: WeatherData asset not displaying properly
|
||||||
|
- rfe: Weather-Data not only for US-Cities
|
||||||
|
- rfe: WeatherData Asset - Convert to International format
|
||||||
- fix: Off by 1 error while displaying ad impressions (perlDreamer Consulting, LLC)
|
- fix: Off by 1 error while displaying ad impressions (perlDreamer Consulting, LLC)
|
||||||
|
|
||||||
7.3.10
|
7.3.10
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@ upgrading from one version to the next, or even between multiple
|
||||||
versions. Be sure to heed the warnings contained herein as they will
|
versions. Be sure to heed the warnings contained herein as they will
|
||||||
save you many hours of grief.
|
save you many hours of grief.
|
||||||
|
|
||||||
|
7.3.11
|
||||||
|
--------------------------------------------------------------------
|
||||||
|
|
||||||
|
* The weather data asset stopped working because our old weather
|
||||||
|
provider went away. We've remade the weather asset using a data
|
||||||
|
feed from weather.com. The feed is free, but you'll have to
|
||||||
|
register to use it on your site. The up side is that the weather
|
||||||
|
asset now supports international cities.
|
||||||
|
|
||||||
7.3.10
|
7.3.10
|
||||||
--------------------------------------------------------------------
|
--------------------------------------------------------------------
|
||||||
* This version fixes a bug in the 7.2.3-7.3.0 upgrade where the
|
* This version fixes a bug in the 7.2.3-7.3.0 upgrade where the
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,18 @@ my $quiet; # this line required
|
||||||
|
|
||||||
my $session = start(); # this line required
|
my $session = start(); # this line required
|
||||||
|
|
||||||
# upgrade functions go here
|
fixWeather($session);
|
||||||
|
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
|
|
||||||
##-------------------------------------------------
|
#-------------------------------------------------
|
||||||
#sub exampleFunction {
|
sub fixWeather {
|
||||||
# my $session = shift;
|
my $session = shift;
|
||||||
# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet);
|
print "\tConverting WeatherData asset to use weather.com\n" unless ($quiet);
|
||||||
# # and here's our code
|
$session->db->write("alter table WeatherData add column partnerId varchar(100)");
|
||||||
#}
|
$session->db->write("alter table WeatherData add column licenseKey varchar(100)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,13 @@ package WebGUI::Asset::File;
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use WebGUI::Asset;
|
use base 'WebGUI::Asset';
|
||||||
use WebGUI::Cache;
|
use WebGUI::Cache;
|
||||||
use WebGUI::Storage;
|
use WebGUI::Storage;
|
||||||
use WebGUI::SQL;
|
use WebGUI::SQL;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
use FileHandle;
|
use FileHandle;
|
||||||
|
|
||||||
our @ISA = qw(WebGUI::Asset);
|
|
||||||
|
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ package WebGUI::Asset::File::ZipArchive;
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use WebGUI::Asset::File;
|
use base 'WebGUI::Asset::File';
|
||||||
use WebGUI::HTMLForm;
|
use WebGUI::HTMLForm;
|
||||||
use WebGUI::SQL;
|
use WebGUI::SQL;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
|
|
@ -23,7 +23,6 @@ use WebGUI::Utility;
|
||||||
use Archive::Tar;
|
use Archive::Tar;
|
||||||
use Archive::Zip;
|
use Archive::Zip;
|
||||||
|
|
||||||
our @ISA = qw(WebGUI::Asset::File);
|
|
||||||
|
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
|
||||||
|
|
@ -12,25 +12,14 @@ package WebGUI::Asset::Wobject::WeatherData;
|
||||||
http://www.plainblack.com info@plainblack.com
|
http://www.plainblack.com info@plainblack.com
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
Portions of the below are originally from Weather::Underground,
|
|
||||||
and are not included in this copyright.
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use Weather::Com::Simple;
|
||||||
use LWP::UserAgent;
|
|
||||||
use Tie::CPHash;
|
|
||||||
use Tie::IxHash;
|
|
||||||
use JSON;
|
|
||||||
use WebGUI::Cache;
|
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::SQL;
|
use base 'WebGUI::Asset::Wobject';
|
||||||
use WebGUI::Asset::Wobject;
|
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
|
|
||||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -46,6 +35,21 @@ sub definition {
|
||||||
my $definition = shift;
|
my $definition = shift;
|
||||||
my $i18n = WebGUI::International->new($session, "Asset_WeatherData");
|
my $i18n = WebGUI::International->new($session, "Asset_WeatherData");
|
||||||
my $properties = {
|
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 =>{
|
templateId =>{
|
||||||
fieldType=>"template",
|
fieldType=>"template",
|
||||||
tab=>"display",
|
tab=>"display",
|
||||||
|
|
@ -56,7 +60,7 @@ sub definition {
|
||||||
},
|
},
|
||||||
locations=>{
|
locations=>{
|
||||||
fieldType=>"textarea",
|
fieldType=>"textarea",
|
||||||
defaultValue=>"Grayslake,IL",
|
defaultValue=>"Madison, WI\nToronto, Canada\n53536",
|
||||||
tab=>"properties",
|
tab=>"properties",
|
||||||
hoverHelp=>$i18n->get("Your list of default weather locations"),
|
hoverHelp=>$i18n->get("Your list of default weather locations"),
|
||||||
label=>$i18n->get("Default 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 )
|
=head2 _chooseWeatherConditionsIcon ( currentSkyConditionsEnglish )
|
||||||
|
|
||||||
Accepts a string that represents the current sky conditions. Taken
|
Accepts a string that represents the current sky conditions. Taken
|
||||||
|
|
@ -228,22 +189,27 @@ to be displayed within the page style
|
||||||
|
|
||||||
sub view {
|
sub view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $var = $self->get();
|
my %var;
|
||||||
#Set some template variables
|
foreach my $location (split("\n", $self->get("locations"))) {
|
||||||
|
my $weather = Weather::Com::Simple->new({
|
||||||
#Build list of locations as an array
|
'partner_id' => $self->get("partnerId"),
|
||||||
my $defaults = $self->get("locations");
|
'license' => $self->get("licenseKey"),
|
||||||
#replace any windows newlines
|
'place' => $location,
|
||||||
$defaults =~ s/\r//gm;
|
'cache' => '/tmp',
|
||||||
my @array = split("\n",$defaults);
|
});
|
||||||
#trim locations of whitespace
|
foreach my $foundLocation (@{$weather->get_weather}) {
|
||||||
my @locs = ();
|
push(@{$var{'ourLocations.loop'}}, {
|
||||||
for (my $i = 0; $i < scalar(@array); $i++) {
|
query => $location,
|
||||||
$array[$i] = $self->_trim($array[$i]);
|
cityState => $foundLocation->{place} || $location,
|
||||||
push(@locs, $self->_getLocationData($array[$i]));
|
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 => [
|
fields => [
|
||||||
|
{
|
||||||
|
title => 'partnerId',
|
||||||
|
description => 'partnerId help',
|
||||||
|
namespace => 'Asset_WeatherData',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title => 'licenseKey',
|
||||||
|
description => 'licenseKey help',
|
||||||
|
namespace => 'Asset_WeatherData',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title => 'Default Locations',
|
title => 'Default Locations',
|
||||||
description => 'Your list of default weather locations',
|
description => 'Your list of default weather locations',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,30 @@
|
||||||
package WebGUI::i18n::English::Asset_WeatherData;
|
package WebGUI::i18n::English::Asset_WeatherData;
|
||||||
|
|
||||||
our $I18N = {
|
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' => {
|
'Current Weather Conditions Template to use' => {
|
||||||
message => q|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' => {
|
'Your list of default weather locations' => {
|
||||||
message => q|Your list of default weather locations, each on its own line. Use City, ST or zipCode.|,
|
message => q{Your list of default weather locations, each on its own line. Usage: City, ST || Zip Code || City, Country},
|
||||||
lastUpdated => 1133619940,
|
lastUpdated => 1172425406,
|
||||||
},
|
},
|
||||||
|
|
||||||
'Default Locations' => {
|
'Default Locations' => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue