summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-12-04 11:29:29 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-12-04 11:29:29 +0100
commit89c18ac4f884ef0588f9c5b7ece85e09291d7912 (patch)
tree37d3031df16d8f546a67efc4d623746e7b2eae42 /share
parenteaddef294b2ad4833c2cb4681d677859b7632c7d (diff)
xml2json: track name changes in separate file
Diffstat (limited to 'share')
-rwxr-xr-xshare/xml2json22
1 files changed, 16 insertions, 6 deletions
diff --git a/share/xml2json b/share/xml2json
index 4591863..02c0821 100755
--- a/share/xml2json
+++ b/share/xml2json
@@ -9,8 +9,9 @@ use JSON;
use List::Util qw(any);
use XML::LibXML;
+my $json = JSON->new->utf8;
my $json_str = read_file('stations.json');
-my $stations = JSON->new->utf8->decode($json_str);
+my $stations = $json->decode($json_str);
@{$stations} = sort { $a->{name} cmp $b->{name} } @{$stations};
my %station_by_ds100;
@@ -37,13 +38,19 @@ my $tree = XML::LibXML->load_xml( string => $xml_str );
my @missing;
-if ( -e "missing.txt" ) {
- for my $line ( read_file("missing.txt") ) {
+if ( -e 'missing.txt' ) {
+ for my $line ( read_file('missing.txt') ) {
chomp $line;
push( @missing, $line );
}
}
+my %renamed;
+if ( -e 'renamed.json' ) {
+ $json_str = read_file('renamed.json');
+ %renamed = %{ $json->decode($json_str) };
+}
+
for my $station ( $tree->findnodes('//station') ) {
my $name = $station->getAttribute('name');
my $eva = $station->getAttribute('eva');
@@ -84,8 +91,8 @@ for my $station ( $tree->findnodes('//station') ) {
{
printf( "%8s has been renamed: %30s -> %30s\n",
$ds100, $station_by_ds100{$ds100}{name}, $name );
-
- #$station_by_ds100{$ds100}{name} = $name;
+ $renamed{ $station_by_ds100{$ds100}{name} } = $name;
+ $station_by_ds100{$ds100}{name} = $name;
}
elsif ( $station_by_eva{$eva} and $station_by_eva{$eva}{name} ne $name ) {
printf(
@@ -159,5 +166,8 @@ for my $i (@to_delete) {
splice( @{$stations}, $i, 1 );
}
-my $json_out = JSON->new->utf8->canonical->pretty->encode($stations);
+my $json_out = $json->canonical->pretty->encode($stations);
write_file( 'stations.json', $json_out );
+
+$json_out = $json->encode( \%renamed );
+write_file( 'renamed.json', $json_out );