forked from supertuxkart/stk-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-countries-table.py
More file actions
executable file
·33 lines (28 loc) · 941 Bytes
/
generate-countries-table.py
File metadata and controls
executable file
·33 lines (28 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
# usage: generate-countries-table.py > countries.csv
# in sqlite3 terminal:
#
# .mode csv
# .headers off
# .separator ";"
# .import 'full path to countries.csv' 'v(database_version)_countries'
#
import csv
import os
import sys
TSV_FILE = '../data/country_names.tsv'
# Use another name in the country_code header if you want countries names in different language
READABLE_NAME = 'en'
# ord("🇦") - ord("A")
FLAG_OFFSET = 127397
if not os.path.exists(TSV_FILE):
print("File = {} does not exist.".format(TSV_FILE))
sys.exit(1)
with open(TSV_FILE, 'r') as tsvfile:
country = csv.DictReader(tsvfile, delimiter='\t', quotechar='"')
# Skip header
next(country)
for row in country:
country_code = row['country_code']
codepoints = [ord(x) + FLAG_OFFSET for x in country_code]
print('%s;%s;%s' % (country_code, chr(codepoints[0]) + chr(codepoints[1]), row[READABLE_NAME]))