This repository was archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunsd_publish03.py
More file actions
54 lines (39 loc) · 1.72 KB
/
unsd_publish03.py
File metadata and controls
54 lines (39 loc) · 1.72 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import utils
import sdg_api
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# ******************************************************************************
# GEOGRAPHY
# ******************************************************************************
# ---------------------------------------------
# Read geographic areas tree and flatten it to
# a parent-child relationship
# ---------------------------------------------
geo = utils.traverse_tree(sdg_api.geoAreaTree(rootCode=1)[0],
parentCode=None,
parentName=None,
itemCode='geoAreaCode',
itemName='geoAreaName',
itemChildren='children',
hierarchy=[],
traverse_level=1)
# ---------------------------------------------
# Add missing areas to geo
# ---------------------------------------------
geo_missing = utils.tsv2dictlist('data/geography/missingAreas.txt')
for gm in geo_missing:
new_dict = dict()
new_dict['level'] = 1
new_dict['parentCode'] = None
new_dict['parentName'] = None
new_dict['geoAreaCode'] = gm['geoAreaCode']
new_dict['geoAreaName'] = gm['geoAreaName']
new_dict['type'] = 'Group'
geo.append(new_dict)
# ---------------------------------------------
# Merge coordinates and list of geographic areas
# ---------------------------------------------
xy_geo = utils.tsv2dictlist('data/geography/refAreas.txt', encoding='latin-1')
geo = utils.merge_dict_lists(geo, xy_geo, ['geoAreaCode'], ['M49'], how='left')
geo = utils.subdict_list(geo, ['M49', 'areaName'], exclude=True)
utils.dictList2tsv(geo, 'data/geography/geo_tree.txt')