added country code to country name, continent name script
This commit is contained in:
parent
93926988ce
commit
c3b10a3008
51
33_country_code.py
Normal file
51
33_country_code.py
Normal file
@ -0,0 +1,51 @@
|
||||
import csv
|
||||
import sys
|
||||
import json
|
||||
|
||||
"""
|
||||
Example usage:
|
||||
|
||||
$ python 33_country_code.py 33_sample_csv.csv 33_country_codes.json
|
||||
"""
|
||||
|
||||
|
||||
def get_data(csv_file, json_file):
|
||||
countryCodes = []
|
||||
countryNames = []
|
||||
continentNames = []
|
||||
with open(csv_file, 'rt') as file_one:
|
||||
reader = csv.reader(file_one)
|
||||
with open(json_file) as file_two:
|
||||
json_data = json.load(file_two)
|
||||
all_countries = json_data["country"]
|
||||
for csv_row in reader:
|
||||
for json_row in all_countries:
|
||||
if csv_row[0] == json_row["countryCode"]:
|
||||
countryCodes.append(json_row["countryCode"])
|
||||
countryNames.append(json_row["countryName"])
|
||||
continentNames.append(json_row["continentName"])
|
||||
|
||||
return [
|
||||
countryCodes,
|
||||
countryNames,
|
||||
continentNames
|
||||
]
|
||||
|
||||
|
||||
def write_data(array_of_arrays):
|
||||
with open('data.csv', 'wt') as csv_out:
|
||||
writer = csv.writer(csv_out)
|
||||
rows = zip(
|
||||
array_of_arrays[0],
|
||||
array_of_arrays[1],
|
||||
array_of_arrays[2]
|
||||
)
|
||||
for row in rows:
|
||||
writer.writerow(row)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
csv_file_name = sys.argv[1]
|
||||
json_file_name = sys.argv[2]
|
||||
data = get_data(csv_file_name, json_file_name)
|
||||
write_data(data)
|
1254
33_country_codes.json
Normal file
1254
33_country_codes.json
Normal file
File diff suppressed because it is too large
Load Diff
109
33_sample_csv.csv
Normal file
109
33_sample_csv.csv
Normal file
@ -0,0 +1,109 @@
|
||||
A2
|
||||
AE
|
||||
AL
|
||||
AP
|
||||
AR
|
||||
AT
|
||||
AU
|
||||
AZ
|
||||
BA
|
||||
BD
|
||||
BE
|
||||
BG
|
||||
BH
|
||||
BN
|
||||
BR
|
||||
BY
|
||||
CA
|
||||
CH
|
||||
CL
|
||||
CN
|
||||
CO
|
||||
CR
|
||||
CW
|
||||
CY
|
||||
CZ
|
||||
DE
|
||||
DK
|
||||
DO
|
||||
EC
|
||||
EE
|
||||
ES
|
||||
FI
|
||||
FR
|
||||
GB
|
||||
GE
|
||||
GG
|
||||
GH
|
||||
GI
|
||||
GR
|
||||
GT
|
||||
HK
|
||||
HR
|
||||
HT
|
||||
HU
|
||||
ID
|
||||
IE
|
||||
IL
|
||||
IN
|
||||
IS
|
||||
IT
|
||||
JM
|
||||
JO
|
||||
JP
|
||||
KE
|
||||
KG
|
||||
KR
|
||||
KW
|
||||
KY
|
||||
KZ
|
||||
LA
|
||||
LB
|
||||
LK
|
||||
LT
|
||||
LU
|
||||
LV
|
||||
MD
|
||||
MG
|
||||
MK
|
||||
MO
|
||||
MT
|
||||
MV
|
||||
MX
|
||||
MY
|
||||
NC
|
||||
NG
|
||||
NI
|
||||
NL
|
||||
NO
|
||||
NP
|
||||
NZ
|
||||
OM
|
||||
PA
|
||||
PE
|
||||
PH
|
||||
PK
|
||||
PL
|
||||
PR
|
||||
PT
|
||||
PY
|
||||
RO
|
||||
RS
|
||||
RU
|
||||
SA
|
||||
SE
|
||||
SG
|
||||
SI
|
||||
SK
|
||||
SO
|
||||
TH
|
||||
TR
|
||||
TW
|
||||
TZ
|
||||
UA
|
||||
US
|
||||
UY
|
||||
VN
|
||||
VU
|
||||
ZA
|
||||
ZW
|
|
107
data.csv
Normal file
107
data.csv
Normal file
@ -0,0 +1,107 @@
|
||||
AE,United Arab Emirates,Asia
|
||||
AL,Albania,Europe
|
||||
AR,Argentina,South America
|
||||
AT,Austria,Europe
|
||||
AU,Australia,Oceania
|
||||
AZ,Azerbaijan,Asia
|
||||
BA,Bosnia and Herzegovina,Europe
|
||||
BD,Bangladesh,Asia
|
||||
BE,Belgium,Europe
|
||||
BG,Bulgaria,Europe
|
||||
BH,Bahrain,Asia
|
||||
BN,Brunei,Asia
|
||||
BR,Brazil,South America
|
||||
BY,Belarus,Europe
|
||||
CA,Canada,North America
|
||||
CH,Switzerland,Europe
|
||||
CL,Chile,South America
|
||||
CN,China,Asia
|
||||
CO,Colombia,South America
|
||||
CR,Costa Rica,North America
|
||||
CW,Curacao,North America
|
||||
CY,Cyprus,Europe
|
||||
CZ,Czechia,Europe
|
||||
DE,Germany,Europe
|
||||
DK,Denmark,Europe
|
||||
DO,Dominican Republic,North America
|
||||
EC,Ecuador,South America
|
||||
EE,Estonia,Europe
|
||||
ES,Spain,Europe
|
||||
FI,Finland,Europe
|
||||
FR,France,Europe
|
||||
GB,United Kingdom,Europe
|
||||
GE,Georgia,Asia
|
||||
GG,Guernsey,Europe
|
||||
GH,Ghana,Africa
|
||||
GI,Gibraltar,Europe
|
||||
GR,Greece,Europe
|
||||
GT,Guatemala,North America
|
||||
HK,Hong Kong,Asia
|
||||
HR,Croatia,Europe
|
||||
HT,Haiti,North America
|
||||
HU,Hungary,Europe
|
||||
ID,Indonesia,Asia
|
||||
IE,Ireland,Europe
|
||||
IL,Israel,Asia
|
||||
IN,India,Asia
|
||||
IS,Iceland,Europe
|
||||
IT,Italy,Europe
|
||||
JM,Jamaica,North America
|
||||
JO,Jordan,Asia
|
||||
JP,Japan,Asia
|
||||
KE,Kenya,Africa
|
||||
KG,Kyrgyzstan,Asia
|
||||
KR,South Korea,Asia
|
||||
KW,Kuwait,Asia
|
||||
KY,Cayman Islands,North America
|
||||
KZ,Kazakhstan,Asia
|
||||
LA,Laos,Asia
|
||||
LB,Lebanon,Asia
|
||||
LK,Sri Lanka,Asia
|
||||
LT,Lithuania,Europe
|
||||
LU,Luxembourg,Europe
|
||||
LV,Latvia,Europe
|
||||
MD,Moldova,Europe
|
||||
MG,Madagascar,Africa
|
||||
MK,Macedonia,Europe
|
||||
MO,Macao,Asia
|
||||
MT,Malta,Europe
|
||||
MV,Maldives,Asia
|
||||
MX,Mexico,North America
|
||||
MY,Malaysia,Asia
|
||||
NC,New Caledonia,Oceania
|
||||
NG,Nigeria,Africa
|
||||
NI,Nicaragua,North America
|
||||
NL,Netherlands,Europe
|
||||
NO,Norway,Europe
|
||||
NP,Nepal,Asia
|
||||
NZ,New Zealand,Oceania
|
||||
OM,Oman,Asia
|
||||
PA,Panama,North America
|
||||
PE,Peru,South America
|
||||
PH,Philippines,Asia
|
||||
PK,Pakistan,Asia
|
||||
PL,Poland,Europe
|
||||
PR,Puerto Rico,North America
|
||||
PT,Portugal,Europe
|
||||
PY,Paraguay,South America
|
||||
RO,Romania,Europe
|
||||
RS,Serbia,Europe
|
||||
RU,Russia,Europe
|
||||
SA,Saudi Arabia,Asia
|
||||
SE,Sweden,Europe
|
||||
SG,Singapore,Asia
|
||||
SI,Slovenia,Europe
|
||||
SK,Slovakia,Europe
|
||||
SO,Somalia,Africa
|
||||
TH,Thailand,Asia
|
||||
TR,Turkey,Asia
|
||||
TW,Taiwan,Asia
|
||||
TZ,Tanzania,Africa
|
||||
UA,Ukraine,Europe
|
||||
US,United States,North America
|
||||
UY,Uruguay,South America
|
||||
VN,Vietnam,Asia
|
||||
VU,Vanuatu,Oceania
|
||||
ZA,South Africa,Africa
|
||||
ZW,Zimbabwe,Africa
|
|
Loading…
Reference in New Issue
Block a user