Skip to content

Commit

Permalink
Clean up pollen type text and fix bug seen with perl 5.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredF committed Jul 6, 2015
1 parent b0a625b commit f33da96
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions code/common/weather_pollen.pl
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@
&parse_pollen_forecast if (($Reload) && (-e $pollen_file));

sub parse_pollen_forecast {
my @pollen_data = file_read($pollen_file) || warn "Unable to open pollen data file.";
my $pollen_data = file_read($pollen_file) || warn "Unable to open pollen data file.";
# The JSON file that is retuned by the service is malformed; these substitutions clean it up so that the perl JSON module can parse it.
for (@pollen_data) {
for ($pollen_data) {
s/\"\{/\{/;
s/\\//g;
s/\}\"/\}/;
}
my $json = decode_json(@pollen_data) || warn "Error parsing pollen info from file.";
my $json = decode_json($pollen_data) || warn "Error parsing pollen info from file.";
$main::Weather{TodayPollenCount} = $json->{pollenForecast}{forecast}[0];
$main::Weather{TomorrowPollenCount} = $json->{pollenForecast}{forecast}[1];
$main::Weather{TodayPollenType} = $json->{pollenForecast}{pp};
# Format the pollen type text to remove any leading spaces or trailing periods.
$main::Weather{TodayPollenType} =~ s/^\s//;
$main::Weather{TodayPollenType} =~ s/\.//;
}

Expand Down

0 comments on commit f33da96

Please sign in to comment.