Skip to content

Commit

Permalink
Add country codes from maxmind csv file
Browse files Browse the repository at this point in the history
use warnings;
use strict;
use Text::CSV qw( csv );

my $d = csv(in => "GeoLite2-Country-Locations-en.csv", headers => "auto");

use Data::Dump qw(pp);

for my $c (sort { $a->{country_iso_code} cmp $b->{country_iso_code}} @$d) {
    next unless $c->{country_name};
    my $cc = lc($c->{country_iso_code});
    my $co = lc($c->{continent_name});
    $co =~ s/\s+/-/;

    unless ($cc) {
        warn pp($c);
        next;
    }

    print qq["$cc":\t"$co",\n];
}
  • Loading branch information
abh committed Dec 29, 2021
1 parent da06a0a commit 7ab39fa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions countries/countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var CountryContinent = map[string]string{
"bm": "north-america",
"bn": "asia",
"bo": "south-america",
"bq": "north-america",
"br": "south-america",
"bs": "north-america",
"bt": "asia",
Expand All @@ -54,8 +55,9 @@ var CountryContinent = map[string]string{
"cr": "north-america",
"cu": "north-america",
"cv": "africa",
"cx": "asia",
"cy": "asia",
"cw": "north-america",
"cx": "oceania",
"cy": "europe",
"cz": "europe",
"de": "europe",
"dj": "africa",
Expand Down Expand Up @@ -210,8 +212,10 @@ var CountryContinent = map[string]string{
"sn": "africa",
"so": "africa",
"sr": "south-america",
"ss": "africa",
"st": "africa",
"sv": "north-america",
"sx": "north-america",
"sy": "asia",
"sz": "africa",
"tc": "north-america",
Expand All @@ -221,7 +225,7 @@ var CountryContinent = map[string]string{
"th": "asia",
"tj": "asia",
"tk": "oceania",
"tl": "asia",
"tl": "oceania",
"tm": "asia",
"tn": "africa",
"to": "oceania",
Expand All @@ -245,6 +249,7 @@ var CountryContinent = map[string]string{
"vu": "oceania",
"wf": "oceania",
"ws": "oceania",
"xk": "europe",
"ye": "asia",
"yt": "africa",
"za": "africa",
Expand Down

0 comments on commit 7ab39fa

Please sign in to comment.