-
Notifications
You must be signed in to change notification settings - Fork 50
/
write-countries.py
35 lines (27 loc) · 1.13 KB
/
write-countries.py
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
34
35
from pathlib import Path
import pandas as pd
this = Path(__file__).name
# read csv file
countries = pd.read_csv("countries.csv", header=None)
# open file and write header
file = open("../countries.yaml", "w")
file.writelines(f"# This file was created using the script `data/{this}`\n")
file.write("# DO NOT ALTER THIS FILE MANUALLY!\n\n")
file.write("# List of countries\n")
file.write("- Countries:\n")
# the EU uses alternative ISO2 codes for some countries
iso2_alternatives = {"GB": "UK", "GR": "EL"}
# write list of countries with dictionary of relevant information
for i, (name, iso2, iso3, eu, syn) in countries.iterrows():
file.write(f" - {name}:\n")
file.write(f" eu_member: {'true' if eu is True else 'false'}\n")
file.write(f" iso2: {iso2}\n")
if iso2 in iso2_alternatives.keys():
file.write(f" iso2_alt: {iso2_alternatives[iso2]}")
file.write(" # the European Commission uses alternative ISO2 codes\n")
file.write(f" iso3: {iso3}\n")
file.write(f" iso3_codes: {iso3}\n")
if isinstance(syn, str):
file.write(f" synonyms: {syn}\n")
# close file
file.close()