Mercurial > hg > egg-tcls
comparison fetch_weather.pl @ 445:dbe9e233f564
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 28 Sep 2017 15:16:40 +0300 |
parents | fe671cd76ecc |
children | ba559d5d44db |
comparison
equal
deleted
inserted
replaced
444:fe671cd76ecc | 445:dbe9e233f564 |
---|---|
386 # Fetch or read the cache | 386 # Fetch or read the cache |
387 my $meta_str; | 387 my $meta_str; |
388 if ($fetch_meta || opt_chk_bool("force_update")) | 388 if ($fetch_meta || opt_chk_bool("force_update")) |
389 { | 389 { |
390 my $uri = opt_get("tiehallinto_meta_url"); | 390 my $uri = opt_get("tiehallinto_meta_url"); |
391 print STDERR "Fetching Tiehallinto static meta data from $uri\n" if (opt_get_int("debug") > 1); | 391 print STDERR "Fetching Tiehallinto static meta data from ".$uri."\n" if (opt_get_int("debug") > 1); |
392 my $res = fetch_http($uri); | 392 my $res = fetch_http($uri); |
393 die("Failed to fetch $uri data.\n") unless ($res->code <= 200 && $res->code <= 201); | 393 die("Failed to fetch $uri data.\n") unless ($res->code <= 200 && $res->code <= 201); |
394 | 394 |
395 $meta_str = $res->decoded_content; | 395 $meta_str = $res->decoded_content; |
396 | 396 |
403 | 403 |
404 $fetch_meta = 1; | 404 $fetch_meta = 1; |
405 } | 405 } |
406 else | 406 else |
407 { | 407 { |
408 print STDERR "Using CACHED Tiehallinto static meta data from '$meta_file'.\n" if (opt_get_int("debug") > 0); | 408 print STDERR "Using CACHED Tiehallinto static meta data from '".$meta_file."'.\n" if (opt_get_int("debug") > 0); |
409 $meta_str = read_text($meta_file); | 409 $meta_str = read_text($meta_file); |
410 } | 410 } |
411 | 411 |
412 print STDERR "Is meta_str UTF8? ".(utf8::is_utf8($meta_str) ? "yes" : "NO!")."\n" if (opt_get_int("debug") > 0); | 412 print STDERR "Is meta_str UTF8? ".(utf8::is_utf8($meta_str) ? "yes" : "NO!")."\n" if (opt_get_int("debug") > 0); |
413 | 413 |
416 my $json = JSON->new->decode($meta_str); | 416 my $json = JSON->new->decode($meta_str); |
417 | 417 |
418 if ($fetch_meta) | 418 if ($fetch_meta) |
419 { | 419 { |
420 # Save new cache, in more optimal form, if needed. | 420 # Save new cache, in more optimal form, if needed. |
421 print STDERR "Storing to cache '$meta_file'.\n" if (opt_get_int("debug") > 0); | 421 print STDERR "Storing to cache '".$meta_file."'.\n" if (opt_get_int("debug") > 0); |
422 write_binary($meta_file, JSON->new->encode($json)); | 422 write_binary($meta_file, JSON->new->encode($json)); |
423 } | 423 } |
424 | 424 |
425 foreach my $ms (@{$json->{"features"}}) | 425 foreach my $ms (@{$json->{"features"}}) |
426 { | 426 { |