Skip to content

Commit c3b10a3

Browse files
committed
added country code to country name, continent name script
1 parent 9392698 commit c3b10a3

File tree

4 files changed

+1521
-0
lines changed

4 files changed

+1521
-0
lines changed

‎33_country_code.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
importcsv
2+
importsys
3+
importjson
4+
5+
"""
6+
Example usage:
7+
8+
$ python 33_country_code.py 33_sample_csv.csv 33_country_codes.json
9+
"""
10+
11+
12+
defget_data(csv_file, json_file):
13+
countryCodes= []
14+
countryNames= []
15+
continentNames= []
16+
withopen(csv_file, 'rt') asfile_one:
17+
reader=csv.reader(file_one)
18+
withopen(json_file) asfile_two:
19+
json_data=json.load(file_two)
20+
all_countries=json_data["country"]
21+
forcsv_rowinreader:
22+
forjson_rowinall_countries:
23+
ifcsv_row[0] ==json_row["countryCode"]:
24+
countryCodes.append(json_row["countryCode"])
25+
countryNames.append(json_row["countryName"])
26+
continentNames.append(json_row["continentName"])
27+
28+
return [
29+
countryCodes,
30+
countryNames,
31+
continentNames
32+
]
33+
34+
35+
defwrite_data(array_of_arrays):
36+
withopen('data.csv', 'wt') ascsv_out:
37+
writer=csv.writer(csv_out)
38+
rows=zip(
39+
array_of_arrays[0],
40+
array_of_arrays[1],
41+
array_of_arrays[2]
42+
)
43+
forrowinrows:
44+
writer.writerow(row)
45+
46+
47+
if__name__=='__main__':
48+
csv_file_name=sys.argv[1]
49+
json_file_name=sys.argv[2]
50+
data=get_data(csv_file_name, json_file_name)
51+
write_data(data)

0 commit comments

Comments
(0)