-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_json_from_web.py
22 lines (15 loc) · 1017 Bytes
/
get_json_from_web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests
import os
import unicodedata
if not os.path.exists('htmls'):
os.makedirs('htmls')
def ra(text):
return (unicodedata.normalize('NFKD', text).encode('ASCII', 'ignore')).decode('utf-8').lower().replace('/', '').replace(' ', ' ').replace(' ', '_')
bairros = ['Brasília','Gama','Taguatinga','Brazlândia','Sobradinho','Planaltina','Paranoá','Núcleo Bandeirante','Ceilândia','Guará','Cruzeiro','Samambaia','Santa Maria','São Sebastião','Recanto das Emas','Lago Sul','Riacho Fundo','Lago Norte','Candangolândia','Águas Claras','Riacho Fundo II','Sudoeste / Octogonal','Varjão','Park Way','SCIA','Sobradinho II','Jardim Botânico','Itapoã','SIA','Vicente Pires','Fercal']
for bairro in bairros:
r = requests.get("https://nominatim.openstreetmap.org/search.php?q=%s+brasilia+distrito+federal&polygon_geojson=1&viewbox=" % bairro.replace(' ', '+'))
html = r.text
file_name = ra(bairro)
fout = open('htmls/'+file_name+'.txt', 'w')
fout.write(html)
fout.close()