-
Notifications
You must be signed in to change notification settings - Fork 0
/
postmon.py
44 lines (32 loc) · 991 Bytes
/
postmon.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
36
37
38
39
40
41
42
43
44
import csv
import json
def _read(filename):
data = []
with open(filename) as f:
reader = csv.DictReader(f)
data.extend(reader)
return data
def ufs():
for line in _read('data/AR_BR_UF_2018.csv'):
yield {
'sigla': line['NM_UF_SIGLA'],
'codigo_ibge': line['CD_GCUF'],
'nome': line['NM_UF'],
'area_km2': line['AR_MUN_2018'],
}
def cidades():
for line in _read('data/AR_BR_MUN_2018.csv'):
yield {
'codigo_ibge_uf': line['CD_GCUF'],
'sigla_uf': line['NM_UF_SIGLA'],
'codigo_ibge': line['CD_GCMUN'],
'nome': line['NM_MUN_2018'],
'area_km2': line['AR_MUN_2018'],
}
def main():
with open('data/postmon/ufs.json', 'w') as f:
json.dump(list(ufs()), f, indent=2)
with open('data/postmon/cidades.json', 'w') as f:
json.dump(list(cidades()), f, indent=2)
if __name__ == '__main__':
main()