Last active
November 10, 2022 21:34
-
-
Save villares/aa24400222fedadf387976fa7c8a299e to your computer and use it in GitHub Desktop.
JSON IBGE / CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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