12 enrich_zips - Utility to add county information to city/state/ZIP data (and optionally use zips.txt format)
16 enrich_zips --db US.txt < citystatezip.tsv
17 enrich_zips --makezips --db US.txt < citystatezip.tsv > zips.txt
21 Geonames database can be downloaded from http://download.geonames.org/export/zip/US.zip
25 my ($db, $makezips, %zips, $warn);
26 my $result = GetOptions ("db=s" => \$db,
27 "makezips" => \$makezips,
30 "Please specify the location of the Geonames database with --db US.txt\n" .
31 "HINT: You can download it at http://download.geonames.org/export/zip/US.zip" .
35 open DB, $db or die "Couldn't open Geonames database $db: $!\n";
37 # Slurp in the Geonames database
41 @{$zips{$f[1]}} = @f[4,2,5];
42 # @{$zips{"33166"}} == ("FL", "Miami Springs", "Miami-Dade")
48 (my $city, my $state, my $zip) = split(/\t/) or next;
50 my ($dbcity, $dbstate);
52 if (defined $zips{$zip}) {
53 ($dbstate, $dbcity, $county) = @{$zips{$zip}};
57 if (!defined $zips{$zip}) {
58 print STDERR "No county data found for ZIP code $zip ($city, $state)\n\n";
61 if ($city ne $dbcity || $state ne $dbstate) {
62 print STDERR "Patron data input says $zip is $city, $state\n".
63 "Geonames database says $zip is $dbcity, $dbstate\n\n";
68 print "|" . join("|", ($state, $city, $zip, "1", "", $county)) . "||\n";
70 print join("\t", ($city, $state, $zip, $county)) . "\n";