Skip to content

Commit c36d581

Browse files
CarduCaldeiraced-certicamilamaia
authored
feat:retorna codigo do ibge do nome do municipio e da uf (#411)
* feat:retorna codigo do ibge do nome do municipio e da uf * feat:altera estrutura do arquivo json usado para obter os codigos dos municipios do IBGE * update CHANGELOG.md and README about get_code_by_municipality_name function * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review * Update tests/ibge/test_municipality.py --------- Co-authored-by: Carlos Eduardo Caldeira <ced@certi.org.br> Co-authored-by: Camila Maia <cmaiacd@gmail.com>
1 parent a46eafe commit c36d581

7 files changed

Lines changed: 5826 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Utilitário `convert_date_to_text`[#394](https://github.com/brazilian-utils/brutils-python/pull/415)
1313
- Utilitário `get_municipality_by_code` [412](https://github.com/brazilian-utils/brutils-python/pull/412)
1414

15+
- Utilitário `get_code_by_municipality_name` [#399](https://github.com/brazilian-utils/brutils-python/issues/399)
16+
1517
## [2.2.0] - 2024-09-12
1618

1719
### Added

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ False
9090
- [format_voter_id](#format_voter_id)
9191
- [generate_voter_id](#generate_voter_id)
9292
- [IBGE](#ibge)
93+
- [get_code_by_municipality_name](#get_code_by_municipality_name)
9394
- [convert_code_to_uf](#convert_code_to_uf)
9495
- [get\_municipality\_by\_code](#get_municipality_by_code)
9596

@@ -1159,6 +1160,36 @@ Example:
11591160
("São Paulo", "SP")
11601161
```
11611162

1163+
### get_code_by_municipality_name
1164+
1165+
Retorna o código IBGE para um dado nome de município e código de UF.
1166+
1167+
Essa função recebe uma string representando o nome de um município e o código da UF, e retorna o código IBGE correspondente (string). A função lida com os nomes ignorando diferenças de maiúsculas, acentos, tratando o caractere "ç" como "c", e ignorando diferenças de maiúsculas para o código da UF.
1168+
1169+
Argumentos:
1170+
* municipality_name (str): O nome do município.
1171+
* uf (str): O código UF do estado.
1172+
1173+
Retorna:
1174+
* str: O código IBGE do município. Retorna None se o nome não for válido ou não existir.
1175+
1176+
Exemplo:
1177+
1178+
```python
1179+
>>> from brutils import get_code_by_municipality_name
1180+
>>> get_code_by_municipality_name("São Paulo", "SP")
1181+
"3550308"
1182+
>>> get_code_by_municipality_name("goiania", "go")
1183+
"5208707"
1184+
>>> get_code_by_municipality_name("Conceição do Coité", "BA")
1185+
"2908408"
1186+
>>> get_code_by_municipality_name("conceicao do Coite", "Ba")
1187+
"2908408"
1188+
>>> get_code_by_municipality_name("Municipio Inexistente", "")
1189+
None
1190+
>>> get_code_by_municipality_name("Municipio Inexistente", "RS")
1191+
None
1192+
```
11621193
# Novos Utilitários e Reportar Bugs
11631194

11641195
Caso queira sugerir novas funcionalidades ou reportar bugs, basta criar

README_EN.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ False
9292
- [IBGE](#ibge)
9393
- [convert_code_to_uf](#convert_code_to_uf)
9494
- [get\_municipality\_by\_code](#get_municipality_by_code)
95+
- [get_code_by_municipality_name](#get_code_by_municipality_name)
9596

9697
## CPF
9798

@@ -1160,6 +1161,40 @@ Example:
11601161
("São Paulo", "SP")
11611162
```
11621163

1164+
### get_code_by_municipality_name
1165+
1166+
Returns the IBGE code for a given municipality name and uf code.
1167+
1168+
This function takes a string representing a municipality's name
1169+
and uf's code and returns the corresponding IBGE code (string). The function
1170+
will handle names by ignoring differences in case, accents, and
1171+
treating the character ç as c and ignoring case differences for the uf code.
1172+
1173+
Args:
1174+
* municipality_name (str): The name of the municipality.
1175+
* uf (str): The uf code of the state.
1176+
1177+
Returns:
1178+
* str: The IBGE code of the municipality. Returns None if the name is not valid or does not exist.
1179+
1180+
Example:
1181+
1182+
```python
1183+
>>> from brutils import get_code_by_municipality_name
1184+
>>> get_code_by_municipality_name("São Paulo", "SP")
1185+
"3550308"
1186+
>>> get_code_by_municipality_name("goiania", "go")
1187+
"5208707"
1188+
>>> get_code_by_municipality_name("Conceição do Coité", "BA")
1189+
"2908408"
1190+
>>> get_code_by_municipality_name("conceicao do Coite", "Ba")
1191+
"2908408"
1192+
>>> get_code_by_municipality_name("Municipio Inexistente", "")
1193+
None
1194+
>>> get_code_by_municipality_name("Municipio Inexistente", "RS")
1195+
None
1196+
```
1197+
11631198
# Feature Request and Bug Report
11641199

11651200
If you want to suggest new features or report bugs, simply create

brutils/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747

4848
# Email Import
4949
from brutils.email import is_valid as is_valid_email
50+
51+
# IBGE Imports
5052
from brutils.ibge.municipality import (
53+
get_code_by_municipality_name,
5154
get_municipality_by_code,
5255
)
53-
54-
# IBGE Imports
5556
from brutils.ibge.uf import (
5657
convert_code_to_uf,
5758
)
@@ -181,4 +182,5 @@
181182
# IBGE
182183
"convert_code_to_uf",
183184
"get_municipality_by_code",
185+
"get_code_by_municipality_name",
184186
]

0 commit comments

Comments
 (0)