diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index fdc22d4b7..53eaa26fa 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,8 @@ 7.3.11 - 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) 7.3.10 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 7a200a90e..3d6f1f679 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -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 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 -------------------------------------------------------------------- * This version fixes a bug in the 7.2.3-7.3.0 upgrade where the diff --git a/docs/upgrades/upgrade_7.3.10-7.3.11.pl b/docs/upgrades/upgrade_7.3.10-7.3.11.pl index 663abd62b..305b4accd 100644 --- a/docs/upgrades/upgrade_7.3.10-7.3.11.pl +++ b/docs/upgrades/upgrade_7.3.10-7.3.11.pl @@ -20,17 +20,18 @@ my $quiet; # this line required my $session = start(); # this line required -# upgrade functions go here +fixWeather($session); finish($session); # this line required -##------------------------------------------------- -#sub exampleFunction { -# my $session = shift; -# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet); -# # and here's our code -#} +#------------------------------------------------- +sub fixWeather { + my $session = shift; + print "\tConverting WeatherData asset to use weather.com\n" unless ($quiet); + $session->db->write("alter table WeatherData add column partnerId varchar(100)"); + $session->db->write("alter table WeatherData add column licenseKey varchar(100)"); +} diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index 8ea183d7a..521916718 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -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 diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm index 26687dfb6..2a73f7072 100644 --- a/lib/WebGUI/Asset/File/ZipArchive.pm +++ b/lib/WebGUI/Asset/File/ZipArchive.pm @@ -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 diff --git a/lib/WebGUI/Asset/Wobject/WeatherData.pm b/lib/WebGUI/Asset/Wobject/WeatherData.pm index 5c974bcd4..dd1f7a362 100644 --- a/lib/WebGUI/Asset/Wobject/WeatherData.pm +++ b/lib/WebGUI/Asset/Wobject/WeatherData.pm @@ -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 => ''.$i18n->get("you need a weather.com key").'', + }, + 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!\s(.*?)
.*?
.*?
.*?
\s(.*?):\s(.*?) °F
!; - - 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}); } diff --git a/lib/WebGUI/Help/Asset_WeatherData.pm b/lib/WebGUI/Help/Asset_WeatherData.pm index 25e6788c1..e7328f913 100644 --- a/lib/WebGUI/Help/Asset_WeatherData.pm +++ b/lib/WebGUI/Help/Asset_WeatherData.pm @@ -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', diff --git a/lib/WebGUI/i18n/English/Asset_WeatherData.pm b/lib/WebGUI/i18n/English/Asset_WeatherData.pm index c7b0b608c..f4c253c47 100644 --- a/lib/WebGUI/i18n/English/Asset_WeatherData.pm +++ b/lib/WebGUI/i18n/English/Asset_WeatherData.pm @@ -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' => {