Mercurial > hg > egg-tcls
comparison fetch_weather.pl @ 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 | c6bbf69afc57 |
children | 330d7e39c8f4 |
comparison
equal
deleted
inserted
replaced
211:bf5818edbff9 | 212:5f04ec60e8d9 |
---|---|
235 { | 235 { |
236 return defined($_[0]->[$_[2]]{"nodes"}[0]{$_[1]}) ? $_[0]->[$_[2]]{"nodes"}[0]{$_[1]} : ""; | 236 return defined($_[0]->[$_[2]]{"nodes"}[0]{$_[1]}) ? $_[0]->[$_[2]]{"nodes"}[0]{$_[1]} : ""; |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 my %th_rain_states = | |
241 ( | |
242 "Pouta" => "Poutaa", | |
243 "Heikko" => "Heikkoa sadetta", | |
244 "Kohtalainen" => "Kohtalaista sadetta", | |
245 "Voimakas" => "Voimakasta sadetta", | |
246 ); | |
247 | |
248 my $th_rain_states_k = join("|", map {quotemeta} sort { length($b)<=>length($a) } keys %th_rain_states); | |
249 | |
250 sub translate_th_rain($) | |
251 { | |
252 my $tmp = $_[0]; | |
253 $tmp =~ s/($th_rain_states_k)/$th_rain_states{$1}/go; | |
254 return $tmp; | |
255 } | |
256 | |
257 | |
240 ### | 258 ### |
241 ### Configuration handling | 259 ### Configuration handling |
242 ### | 260 ### |
243 sub opt_chk_bool($) | 261 sub opt_chk_bool($) |
244 { | 262 { |
381 | 399 |
382 my $oelems = fnode($odata, "table")->{"nodes"}; | 400 my $oelems = fnode($odata, "table")->{"nodes"}; |
383 for (my $n = 1; $n < scalar(@$oelems); $n++) | 401 for (my $n = 1; $n < scalar(@$oelems); $n++) |
384 { | 402 { |
385 my $fdata = @$oelems[$n]->{"nodes"}; | 403 my $fdata = @$oelems[$n]->{"nodes"}; |
386 $weatherdata->{$fdata->[0]{"nodes"}[0]{"text"}} = | 404 $weatherdata->{get_node($fdata, "text", 0)} = |
387 [ | 405 [ |
388 0, | 406 0, |
389 parse_timestamp(get_node($fdata, "text", 1), $time_base), | 407 parse_timestamp(get_node($fdata, "text", 1), $time_base), |
390 get_node($fdata, "text", 2), | 408 get_node($fdata, "text", 2), |
391 get_node($fdata, "text", 3), | 409 get_node($fdata, "text", 3), |
392 get_node($fdata, "text", 4), | 410 translate_th_rain(get_node($fdata, "text", 4)), |
411 get_node($fdata, "text", 5), | |
393 ]; | 412 ]; |
394 } | 413 } |
395 } | 414 } |
396 } | 415 } |
397 } | 416 } |