csv2json implemented
authorNeszt Tibor <neszt.tibor@euronetrt.hu>
Wed, 6 May 2020 15:37:10 +0000 (17:37 +0200)
committerNeszt Tibor <neszt.tibor@euronetrt.hu>
Wed, 6 May 2020 15:37:10 +0000 (17:37 +0200)
csv2json.pl [new file with mode: 0755]
update.sh.sample

diff --git a/csv2json.pl b/csv2json.pl
new file mode 100755 (executable)
index 0000000..d8f21bf
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use JSON::XS;
+
+sub main {
+       my $csvfilename = shift // die "Must give csv filename!";
+
+       $csvfilename =~ s/.csv$//;
+
+       my $stat = {};
+
+       while (<>) {
+               /^(.*?),(.*?),(.*?),(.*?)$/ or die "Invalid csv line! [$_]";
+               my $zip = $1;
+               my $city = $2;
+               my $street = $3;
+               my $housenumber = $4;
+
+               next if !$zip;
+               next if !$city;
+
+               $stat->{cities}->{$city}->{$zip} = 1;
+               $stat->{zips}->{$zip}->{$city} = 1;
+       }
+
+       foreach my $city ( keys %{$stat->{cities}} ) {
+               $stat->{cities}->{$city} = [keys %{$stat->{cities}->{$city}}];
+       }
+
+       foreach my $zip ( keys %{$stat->{zips}} ) {
+               $stat->{zips}->{$zip} = [keys %{$stat->{zips}->{$zip}}];
+       }
+
+       my $ff;
+
+       open($ff, ">$csvfilename-cities-with-zips.json");
+       print $ff JSON::XS->new->canonical()->pretty()->encode($stat->{cities});
+       close($ff);
+
+       open($ff, ">$csvfilename-zips-with-cities.json");
+       print $ff JSON::XS->new->canonical()->pretty()->encode($stat->{zips});
+       close($ff);
+
+       return 0;
+}
+
+exit main(@ARGV);
index ee62800..451d57a 100755 (executable)
@@ -25,6 +25,11 @@ osmconvert hungary-latest-filtered.osm --all-to-nodes --csv="addr:postcode addr:
 echo -n "Osmconvert finished "
 date
 
-git add hungary-latest-filtered.csv
+./csv2json.pl hungary-latest-filtered.csv
+
+echo -n "Generating json files finished "
+date
+
+git add hungary-latest-filtered.csv hungary-latest-filtered-*
 GIT_AUTHOR_EMAIL='example@example.com' GIT_COMMITTER_EMAIL='example@example.com' git commit -m 'hungary-latest-filtered.csv daily update'
 git push