Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:retorna codigo do ibge do nome do municipio e da uf #411

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

- Utilitário `get_code_by_municipality_name` [#399](https://github.com/brazilian-utils/brutils-python/issues/399)

## [2.2.0] - 2024-09-12

### Added
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ False
- [format_voter_id](#format_voter_id)
- [generate_voter_id](#generate_voter_id)
- [IBGE](#ibge)
- [get_code_by_municipality_name](#get_code_by_municipality_name)
- [convert_code_to_uf](#convert_code_to_uf)
- [get\_municipality\_by\_code](#get_municipality_by_code)

Expand Down Expand Up @@ -1159,6 +1160,36 @@ Example:
("São Paulo", "SP")
```

### get_code_by_municipality_name

Retorna o código IBGE para um dado nome de município e código de UF.

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.

Argumentos:
* municipality_name (str): O nome do município.
* uf (str): O código UF do estado.

Retorna:
* str: O código IBGE do município. Retorna None se o nome não for válido ou não existir.

Exemplo:
camilamaia marked this conversation as resolved.
Show resolved Hide resolved
camilamaia marked this conversation as resolved.
Show resolved Hide resolved

```python
>>> from brutils import get_code_by_municipality_name
>>> get_code_by_municipality_name("São Paulo", "SP")
"3550308"
>>> get_code_by_municipality_name("goiania", "go")
"5208707"
>>> get_code_by_municipality_name("Conceição do Coité", "BA")
"2908408"
>>> get_code_by_municipality_name("conceicao do Coite", "Ba")
"2908408"
>>> get_code_by_municipality_name("Municipio Inexistente", "")
None
>>> get_code_by_municipality_name("Municipio Inexistente", "RS")
None
```
# Novos Utilitários e Reportar Bugs

Caso queira sugerir novas funcionalidades ou reportar bugs, basta criar
Expand Down
35 changes: 35 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ False
- [IBGE](#ibge)
- [convert_code_to_uf](#convert_code_to_uf)
- [get\_municipality\_by\_code](#get_municipality_by_code)
- [get_code_by_municipality_name](#get_code_by_municipality_name)

## CPF

Expand Down Expand Up @@ -1160,6 +1161,40 @@ Example:
("São Paulo", "SP")
```

### get_code_by_municipality_name

Returns the IBGE code for a given municipality name and uf code.

This function takes a string representing a municipality's name
and uf's code and returns the corresponding IBGE code (string). The function
will handle names by ignoring differences in case, accents, and
treating the character ç as c and ignoring case differences for the uf code.

Args:
* municipality_name (str): The name of the municipality.
* uf (str): The uf code of the state.

Returns:
* str: The IBGE code of the municipality. Returns None if the name is not valid or does not exist.

Example:

```python
>>> from brutils import get_code_by_municipality_name
>>> get_code_by_municipality_name("São Paulo", "SP")
"3550308"
>>> get_code_by_municipality_name("goiania", "go")
"5208707"
>>> get_code_by_municipality_name("Conceição do Coité", "BA")
"2908408"
>>> get_code_by_municipality_name("conceicao do Coite", "Ba")
"2908408"
>>> get_code_by_municipality_name("Municipio Inexistente", "")
None
>>> get_code_by_municipality_name("Municipio Inexistente", "RS")
None
```

# Feature Request and Bug Report

If you want to suggest new features or report bugs, simply create
Expand Down
6 changes: 4 additions & 2 deletions brutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@

# Email Import
from brutils.email import is_valid as is_valid_email

# IBGE Imports
from brutils.ibge.municipality import (
get_code_by_municipality_name,
get_municipality_by_code,
)

# IBGE Imports
from brutils.ibge.uf import (
convert_code_to_uf,
)
Expand Down Expand Up @@ -181,4 +182,5 @@
# IBGE
"convert_code_to_uf",
"get_municipality_by_code",
"get_code_by_municipality_name",
]
Loading
Loading