Last active
August 29, 2015 14:00
-
-
Save theist/11375357 to your computer and use it in GitHub Desktop.
GeoLiteCity to ngx geo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# | |
sub dec2ip ($) { | |
join '.', unpack 'C4', pack 'N', shift; # copied from the hive mind | |
} | |
open (LOCS, '<GeoLiteCity-Location.csv'); | |
my %es_locs; | |
my @fields; | |
while (<LOCS>) { | |
next unless (/ES/); # keep only ES | |
s/\"//g; | |
@fields = split(/,/); | |
next unless $fields[3]; # keep non-empty locations | |
s/\'//g; | |
$es_locs{$fields[0]} = $fields[3]; | |
} | |
close(LOCS); | |
open(BLOCKS, '<GeoLiteCity-Blocks.csv'); | |
open(RES, '>result.csv'); | |
while (<BLOCKS>){ | |
chomp; | |
s/\"//g; | |
@fields = split(/,/); | |
next unless defined($es_locs{$fields[2]}); | |
print RES " ". dec2ip($fields[0])."-". dec2ip($fields[1]). " '" . $es_locs{$fields[2]} ."';\n"; | |
} | |
close(BLOCKS); | |
close(RES); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment