comparison fetch_weather.pl @ 413:b63525aed190

fetch_weather: Unfortunately we have to deal with some UTF-8 brokenness here.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Jan 2017 22:36:34 +0200
parents e0d86ccef873
children d623652df6b5
comparison
equal deleted inserted replaced
412:e0d86ccef873 413:b63525aed190
359 print STDERR "Fetching Tiehallinto static meta data from $uri\n" if (opt_get_int("debug") > 1); 359 print STDERR "Fetching Tiehallinto static meta data from $uri\n" if (opt_get_int("debug") > 1);
360 my $res = fetch_http($uri); 360 my $res = fetch_http($uri);
361 die("Failed to fetch $uri data.\n") unless ($res->code <= 200 && $res->code <= 201); 361 die("Failed to fetch $uri data.\n") unless ($res->code <= 200 && $res->code <= 201);
362 362
363 $meta_str = $res->decoded_content; 363 $meta_str = $res->decoded_content;
364
365 # XXX: This is a hack. For some reason the data does not get utf8 flagged internally.
366 if (!utf8::is_utf8($meta_str))
367 {
368 printf STDERR "Upgrading meta_str to UTF-8.\n" if (opt_get_int("debug") > 0);
369 utf8::upgrade($meta_str);
370 }
371
364 $fetch_meta = 1; 372 $fetch_meta = 1;
365 } 373 }
366 else 374 else
367 { 375 {
368 print STDERR "Using CACHED Tiehallinto static meta data from '$meta_file'.\n" if (opt_get_int("debug") > 0); 376 print STDERR "Using CACHED Tiehallinto static meta data from '$meta_file'.\n" if (opt_get_int("debug") > 0);
369 $meta_str = read_text($meta_file, "utf-8"); 377 $meta_str = read_text($meta_file, "utf-8");
370 } 378 }
379
380 print STDERR "Is meta_str UTF8? ".(utf8::is_utf8($meta_str) ? "yes" : "NO!")."\n" if (opt_get_int("debug") > 1);
371 381
372 # Parse the data .. 382 # Parse the data ..
373 my $meta_data = {}; 383 my $meta_data = {};
374 my $json = JSON->new->decode($meta_str); 384 my $json = JSON->new->decode($meta_str);
375 385