Skip to content

Instantly share code, notes, and snippets.

@villares
Last active November 10, 2022 21:34
Show Gist options
  • Save villares/aa24400222fedadf387976fa7c8a299e to your computer and use it in GitHub Desktop.
Save villares/aa24400222fedadf387976fa7c8a299e to your computer and use it in GitHub Desktop.
JSON IBGE / CSV
import csv
from urllib.request import Request, urlopen
# I used the publish feature from a Google Spreadsheet
url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vT7etkg--Axh_CJlmZdlJ3rrE71rZ10kNQpbqUr8rcPL8WLNepgaIJMN6ZbUHbscjBv014rjaB9Qkwy/pub?gid=0&single=true&output=csv" # change to your own!
response = urlopen(Request(url))
content = response.read().decode('utf-8')
data = csv.DictReader(content.splitlines())
cols = data.fieldnames
print(cols)
rows = list(data)
print(len(rows))
print(rows[0])
import requests # precisa instalr esta lib
distritos = 'https://servicodados.ibge.gov.br/api/v1/localidades/distritos?orderBy=nome'
request = requests.get(distritos)
json_ibge = request.json()
for r in json_ibge:
if 'Abadia' in r['nome']:
print(r['id'], r['nome'], r['municipio']['nome'],
r['municipio']['microrregiao']['nome'], sep=' - ')
#print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment