Merge pull request #682 from strukturag/continentmap-source

Update source of continentmap to original CSV file.
This commit is contained in:
Joachim Bauch 2024-03-11 10:49:19 +01:00 committed by GitHub
commit 1a93c42c38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 6 deletions

View file

@ -1,6 +1,18 @@
name: check-continentmap
on:
push:
branches: [ master ]
paths:
- '.github/workflows/check-continentmap.yml'
- 'scripts/get_continent_map.py'
- 'Makefile'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/check-continentmap.yml'
- 'scripts/get_continent_map.py'
- 'Makefile'
schedule:
- cron: "0 2 * * SUN"

View file

@ -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{

View file

@ -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)