Mercurial > hg > egg-tcls
changeset 212:5f04ec60e8d9
weather: "Translate" rain state from Tiehallitus data.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Sep 2014 21:40:49 +0300 |
parents | bf5818edbff9 |
children | 330d7e39c8f4 |
files | fetch_weather.pl |
diffstat | 1 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/fetch_weather.pl Wed Sep 24 21:40:14 2014 +0300 +++ b/fetch_weather.pl Wed Sep 24 21:40:49 2014 +0300 @@ -237,6 +237,24 @@ } +my %th_rain_states = +( + "Pouta" => "Poutaa", + "Heikko" => "Heikkoa sadetta", + "Kohtalainen" => "Kohtalaista sadetta", + "Voimakas" => "Voimakasta sadetta", +); + +my $th_rain_states_k = join("|", map {quotemeta} sort { length($b)<=>length($a) } keys %th_rain_states); + +sub translate_th_rain($) +{ + my $tmp = $_[0]; + $tmp =~ s/($th_rain_states_k)/$th_rain_states{$1}/go; + return $tmp; +} + + ### ### Configuration handling ### @@ -383,13 +401,14 @@ for (my $n = 1; $n < scalar(@$oelems); $n++) { my $fdata = @$oelems[$n]->{"nodes"}; - $weatherdata->{$fdata->[0]{"nodes"}[0]{"text"}} = + $weatherdata->{get_node($fdata, "text", 0)} = [ 0, parse_timestamp(get_node($fdata, "text", 1), $time_base), get_node($fdata, "text", 2), get_node($fdata, "text", 3), - get_node($fdata, "text", 4), + translate_th_rain(get_node($fdata, "text", 4)), + get_node($fdata, "text", 5), ]; } }