From b0f2e6ea335060a3103b6fa717debf488d75b9cd Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Mon, 11 Mar 2024 10:36:38 +0100 Subject: [PATCH] Update source of continentmap to original CSV file. Now fetching from https://github.com/datasets/country-codes repository. --- continentmap.go | 2 +- scripts/get_continent_map.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/continentmap.go b/continentmap.go index 3da979a..9e66ebf 100644 --- a/continentmap.go +++ b/continentmap.go @@ -1,7 +1,7 @@ package signaling // This file has been automatically generated, do not modify. -// Source: https://datahub.io/core/country-codes/r/country-codes.json +// Source: https://github.com/datasets/country-codes/raw/master/data/country-codes.csv var ( ContinentMap = map[string][]string{ diff --git a/scripts/get_continent_map.py b/scripts/get_continent_map.py index 22dead6..3a96224 100755 --- a/scripts/get_continent_map.py +++ b/scripts/get_continent_map.py @@ -26,11 +26,11 @@ try: from cStringIO import StringIO except ImportError: from io import StringIO -import json +import csv import subprocess import sys -URL = 'https://datahub.io/core/country-codes/r/country-codes.json' +URL = 'https://github.com/datasets/country-codes/raw/master/data/country-codes.csv' def tostr(s): if isinstance(s, bytes) and not isinstance(s, str): @@ -55,12 +55,13 @@ def generate_map(filename): '-L', URL, ]) - data = json.loads(tostr(data)) + + reader = csv.DictReader(StringIO(tostr(data)), delimiter=',') continents = {} - for entry in data: + for entry in reader: country = entry['ISO3166-1-Alpha-2'] continent = entry['Continent'] - if country is None and continent is None: + if not country and not continent: continue continents.setdefault(country, []).append(continent)