Skip to content

Instantly share code, notes, and snippets.

@jtsilverio
Last active December 12, 2023 00:29
Show Gist options
  • Select an option

  • Save jtsilverio/140ef588d8d9ba0f35abc44f9fc410f0 to your computer and use it in GitHub Desktop.

Select an option

Save jtsilverio/140ef588d8d9ba0f35abc44f9fc410f0 to your computer and use it in GitHub Desktop.
import json
import requests
ESTADOS_BRASILEIROS = (
("AC", "Acre"),
("AL", "Alagoas"),
("AP", "Amapá"),
("AM", "Amazonas"),
("BA", "Bahia"),
("CE", "Ceará"),
("DF", "Distrito Federal"),
("ES", "Espírito Santo"),
("GO", "Goiás"),
("MA", "Maranhão"),
("MT", "Mato Grosso"),
("MS", "Mato Grosso do Sul"),
("MG", "Minas Gerais"),
("PA", "Pará"),
("PB", "Paraíba"),
("PR", "Paraná"),
("PE", "Pernambuco"),
("PI", "Piauí"),
("RJ", "Rio de Janeiro"),
("RN", "Rio Grande do Norte"),
("RS", "Rio Grande do Sul"),
("RO", "Rondônia"),
("RR", "Roraima"),
("SC", "Santa Catarina"),
("SP", "São Paulo"),
("SE", "Sergipe"),
("TO", "Tocantins"),
)
all_states = [state[0] for state in ESTADOS_BRASILEIROS]
all_states = "|".join(all_states)
response = requests.get(
f"https://servicodados.ibge.gov.br/api/v1/localidades/estados/{all_states}/municipios"
)
data = response.json()
with open("apps/cidades/generate_fixtures/cidades_ibge.json", "w") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment