Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update source of continentmap to original CSV file. #682

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/check-continentmap.yml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion continentmap.go
Original file line number Diff line number Diff line change
@@ -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{
Expand Down
11 changes: 6 additions & 5 deletions scripts/get_continent_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
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):
Expand All @@ -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)
Expand Down
Loading