Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ http://developer.omie.com.br/service-list/
- [Delphi](https://github.com/omiexperience/api-examples/tree/master/delphi)
- [DotNet](https://github.com/omiexperience/api-examples/tree/master/dotnet)
- [PHP](https://github.com/omiexperience/api-examples/tree/master/php)
- [Python](https://github.com/iepsenn/api-examples/tree/master/python)

## Como testar as API's

Expand Down
19 changes: 19 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Extraindo dados da API utilizando Python

## Pré-requisitos
O único prerequisito pode ser instalado com o seguinte comando:
```
pip install PyYAML
```

## Arquivos de configuração
* `keys.yaml`
Chaves da API a serem usadas no extrator.
* `routes.yaml`
Rotas e método a ser acessado.

## Execução
Basta mudar os parâmetros nos arquivos de configuração e rodar o script `extractor.py`


[Link](https://github.com/iepsenn/omie-extractor) para extrator de dados um pouco mais completo.
47 changes: 47 additions & 0 deletions python/extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import yaml

url = 'https://app.omie.com.br/api/v1/'

# Lendo arquivos de configuração
with open('./keys.yaml') as file:
keys = yaml.load(file, Loader=yaml.FullLoader)

with open('./routes.yaml') as file:
routes = yaml.load(file, Loader=yaml.FullLoader)

# Atribuindo chaves da api para variaveis
app_key = keys['app_key']
app_secret = keys['app_secret']

route = routes['route']
call = routes['call']

# Parâmetros para requisição
params = {
"call": "{}".format(call),
"app_key": "{}".format(app_key),
"app_secret": "{}".format(app_secret),
"param": [
{
"registros_por_pagina": 10,
"apenas_importado_api": "N"
}
]
}

# Formata o url para pegar os dados
url_api = '{}{}?JSON={}'.format(
url,
route,
str(params).replace('\'', "\"")
)

# Fazendo a request pra página
response = requests.get(url_api)

# Testa se deu tudo certo
if response.status_code == 200:
print(response.json()[list(response.json().keys())[-1]])
else:
print('Requisição falhou')
2 changes: 2 additions & 0 deletions python/keys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app_key: 1560731700
app_secret: "226dcf372489bb45ceede61bfd98f0f1"
2 changes: 2 additions & 0 deletions python/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
route: "geral/produtos/"
call: "ListarProdutos"