Skip to content

Commit 8dbcd26

Browse files
committed
added continent metadata to countries in flags fixture
1 parent a786180 commit 8dbcd26

File tree

4 files changed

+258
-0
lines changed

4 files changed

+258
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Source for continent listings:
2+
# United Nations Statistics Division
3+
# http://unstats.un.org/unsd/cr/ctryreg/default.asp?Lg=1
4+
5+
CONTINENTS = dict(AF='Africa',
6+
AS='Asia',
7+
EU='Europe',
8+
NA='North America',
9+
SA='South America',
10+
OC='Oceania')
11+
12+
COUNTRY_CONTINENT = {}
13+
14+
for cont_code, cont_name in CONTINENTS.items():
15+
cont_suffix = cont_name.lower().replace(' ', '_')
16+
with open('continent-' + cont_suffix + '.txt') as fp:
17+
for country in fp:
18+
COUNTRY_CONTINENT[country.strip()] = cont_code
19+
20+
with open('country-codes.tab') as fp:
21+
for lin in fp:
22+
if lin.startswith('#'):
23+
continue
24+
lin = lin.strip()
25+
cc, gec, name = lin.split('\t')
26+
cont = COUNTRY_CONTINENT.get(name, '??')
27+
print(cc, gec, cont, name, sep='\t')
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Build flags fixture
3+
"""
4+
5+
import shutil
6+
import os
7+
import json
8+
9+
SRC = 'img/'
10+
DEST = 'fixture/'
11+
CONTINENTS = dict(AF='Africa',
12+
AS='Asia',
13+
EU='Europe',
14+
NA='North America',
15+
SA='South America',
16+
OC='Oceania')
17+
18+
with open('countries-continents.tab') as cc_fp:
19+
for line in cc_fp:
20+
if line.startswith('#'):
21+
continue
22+
iso_cc, gec_cc, cont, name = line.strip().split('\t')
23+
print(iso_cc, name)
24+
cc = iso_cc.lower()
25+
img_name = cc + '.gif'
26+
from_file = os.path.join(SRC, img_name)
27+
to_path = os.path.join(DEST, cc)
28+
os.mkdir(to_path)
29+
to_file = os.path.join(to_path, img_name)
30+
shutil.copyfile(from_file, to_file)
31+
tld_cc = 'uk' if cc == 'gb' else cc
32+
metadata = {'country': name, 'continent':CONTINENTS[cont],
33+
'iso_cc': iso_cc, 'tld_cc': '.'+tld_cc, 'gec_cc': gec_cc}
34+
35+
with open(os.path.join(to_path, 'metadata.json'), 'wt') as json_fp:
36+
json.dump(metadata, json_fp, ensure_ascii=True)
2.22 KB
Binary file not shown.
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# ISO-3166-1 US-GEC continent name
2+
AF AF AS Afghanistan
3+
AL AL EU Albania
4+
DZ AG AF Algeria
5+
AD AN EU Andorra
6+
AO AO AF Angola
7+
AG AC NA Antigua and Barbuda
8+
AR AR SA Argentina
9+
AM AM AS Armenia
10+
AU AS OC Australia
11+
AT AU EU Austria
12+
AZ AJ AS Azerbaijan
13+
BS BF NA Bahamas
14+
BH BA AS Bahrain
15+
BD BG AS Bangladesh
16+
BB BB NA Barbados
17+
BY BO EU Belarus
18+
BE BE EU Belgium
19+
BZ BH NA Belize
20+
BJ BN AF Benin
21+
BT BT AS Bhutan
22+
BO BL SA Bolivia
23+
BA BK EU Bosnia and Herzegovina
24+
BW BC AF Botswana
25+
BR BR SA Brazil
26+
BN BX AS Brunei Darussalam
27+
BG BU EU Bulgaria
28+
BF UV AF Burkina Faso
29+
BI BY AF Burundi
30+
KH CB AS Cambodia
31+
CM CM AF Cameroon
32+
CA CA NA Canada
33+
CV CV AF Cape Verde
34+
CF CT AF Central African Republic
35+
TD CD AF Chad
36+
CL CI SA Chile
37+
CN CH AS China
38+
CO CO SA Colombia
39+
KM CN AF Comoros
40+
CG CF AF Congo (Brazzaville)
41+
CD CG AF Congo (Kinshasa)
42+
CR CS NA Costa Rica
43+
CI IV AF Côte d'Ivoire
44+
HR HR EU Croatia
45+
CU CU NA Cuba
46+
CY CY AS Cyprus
47+
CZ EZ EU Czech Republic
48+
DK DA EU Denmark
49+
DJ DJ AF Djibouti
50+
DM DO NA Dominica
51+
EC EC SA Ecuador
52+
EG EG AF Egypt
53+
SV ES NA El Salvador
54+
GQ EK AF Equatorial Guinea
55+
ER ER AF Eritrea
56+
EE EN EU Estonia
57+
ET ET AF Ethiopia
58+
FJ FJ OC Fiji
59+
FI FI EU Finland
60+
FR FR EU France
61+
GA GB AF Gabon
62+
GM GA AF Gambia
63+
GE GG AS Georgia
64+
DE GM EU Germany
65+
GH GH AF Ghana
66+
GR GR EU Greece
67+
GD GJ NA Grenada
68+
GT GT NA Guatemala
69+
GN GV AF Guinea
70+
GW PU AF Guinea-Bissau
71+
GY GY SA Guyana
72+
HT HA NA Haiti
73+
HN HO NA Honduras
74+
HU HU EU Hungary
75+
IS IC EU Iceland
76+
IN IN AS India
77+
ID ID AS Indonesia
78+
IR IR AS Iran
79+
IQ IZ AS Iraq
80+
IE EI EU Ireland
81+
IL IS AS Israel
82+
IT IT EU Italy
83+
JM JM NA Jamaica
84+
JP JA AS Japan
85+
JO JO AS Jordan
86+
KZ KZ AS Kazakhstan
87+
KE KE AF Kenya
88+
KI KR OC Kiribati
89+
KP KN AS Korea, North
90+
KR KS AS Korea, South
91+
KW KU AS Kuwait
92+
KG KG AS Kyrgyzstan
93+
LA LA AS Laos
94+
LV LG EU Latvia
95+
LB LE AS Lebanon
96+
LS LT AF Lesotho
97+
LR LI AF Liberia
98+
LY LY AF Libya
99+
LI LS EU Liechtenstein
100+
LT LH EU Lithuania
101+
LU LU EU Luxembourg
102+
MK MK EU Macedonia
103+
MG MA AF Madagascar
104+
MW MI AF Malawi
105+
MY MY AS Malaysia
106+
MV MV AF Maldives
107+
ML ML AF Mali
108+
MT MT EU Malta
109+
MH RM OC Marshall Islands
110+
MR MR AF Mauritania
111+
MU MP AF Mauritius
112+
MX MX NA Mexico
113+
FM FM OC Micronesia
114+
MD MD EU Moldova
115+
MC MN EU Monaco
116+
MN MG AS Mongolia
117+
ME MJ EU Montenegro
118+
MA MO AF Morocco
119+
MZ MZ AF Mozambique
120+
MM BM AS Myanmar
121+
NA WA AF Namibia
122+
NR NR OC Nauru
123+
NP NP AS Nepal
124+
NL NL EU Netherlands
125+
NZ NZ OC New Zealand
126+
NI NU NA Nicaragua
127+
NE NG AF Niger
128+
NG NI AF Nigeria
129+
NO NO EU Norway
130+
OM MU AS Oman
131+
PK PK AS Pakistan
132+
PW PS OC Palau
133+
PA PM NA Panama
134+
PG PP OC Papua New Guinea
135+
PY PA SA Paraguay
136+
PE PE SA Peru
137+
PH RP AS Philippines
138+
PL PL EU Poland
139+
PT PO EU Portugal
140+
QA QA AS Qatar
141+
RO RO EU Romania
142+
RU RS EU Russian Federation
143+
RW RW AF Rwanda
144+
KN SC NA Saint Kitts and Nevis
145+
LC ST NA Saint Lucia
146+
VC VC NA Grenadines
147+
WS WS OC Samoa
148+
SM SM EU San Marino
149+
ST TP AF Sao Tome and Principe
150+
SA SA AS Saudi Arabia
151+
SN SG AF Senegal
152+
RS RI EU Serbia
153+
SC SE AF Seychelles
154+
SL SL AF Sierra Leone
155+
SG SN AS Singapore
156+
SK LO EU Slovakia
157+
SI SI EU Slovenia
158+
SB BP OC Solomon Islands
159+
SO SO AF Somalia
160+
ZA SF AF South Africa
161+
SS OD AF South Sudan
162+
ES SP EU Spain
163+
LK CE AS Sri Lanka
164+
SD SU AF Sudan
165+
SR NS SA Suriname
166+
SZ WZ AF Swaziland
167+
SE SW EU Sweden
168+
CH SZ EU Switzerland
169+
SY SY AS Syria
170+
TW TW AS Taiwan
171+
TJ TI AS Tajikistan
172+
TZ TZ AF Tanzania
173+
TH TH AS Thailand
174+
TL TT OC Timor-Leste
175+
TG TO AF Togo
176+
TO TN OC Tonga
177+
TT TD NA Trinidad and Tobago
178+
TN TS AF Tunisia
179+
TR TU AS Turkey
180+
TM TX AS Turkmenistan
181+
TV TV OC Tuvalu
182+
UG UG AF Uganda
183+
UA UP EU Ukraine
184+
AE AE AS United Arab Emirates
185+
GB UK EU United Kingdom
186+
US US NA United States of America
187+
UY UY SA Uruguay
188+
UZ UZ AS Uzbekistan
189+
VU NH OC Vanuatu
190+
VA VT EU Vatican City
191+
VE VE SA Venezuela
192+
VN VM AS Vietnam
193+
YE YM AS Yemen
194+
ZM ZA AF Zambia
195+
ZW ZI AF Zimbabwe

0 commit comments

Comments
 (0)