Skip to content

Instantly share code, notes, and snippets.

@theist
Last active August 29, 2015 14:00
Show Gist options
  • Save theist/11375357 to your computer and use it in GitHub Desktop.
Save theist/11375357 to your computer and use it in GitHub Desktop.
GeoLiteCity to ngx geo
#!/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