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
24 changes: 20 additions & 4 deletions apis/apicorreios.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import sys
from datetime import date
from workadays.workdays import networkdays
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faltou atualizar o pyproject.toml com a nova dependência, né?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faltou só adicionar o poetry.lock atualizado. Por isso falhou o teste.

Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.

from rastreio import db

import aiohttp
Expand All @@ -21,6 +22,20 @@
finished_code = config['CORREIOS']['FCODE']
batch_size = int(config['RASTREIOBOT']['batch_size'])

def parse_data(delta_dias, delta_dias_uteis):
if delta_dias == 1:
data = ' (' + str(delta_dias) + ' dia'
elif delta_dias > 1:
data = ' (' + str(delta_dias) + ' dias'

if delta_dias_uteis == 1:
data = data + ' – ' + str(delta_dias_uteis) + ' dia útil)'
elif delta_dias_uteis > 1:
data = data + ' – ' + str(delta_dias_uteis) + ' dias úteis)'
elif delta_dias > 0:
data = data + ')'

return data
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! Boa! Só fica melhor se puder adicionar alguns testes pra essa função! 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estou com um pouco de dificuldade de entender exatamente como fazer, mas vou dar uma olhada

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse teste talvez seja um bom exemplo, avisa aqui se não tiver dando certo.


def parse(code, tabela):
if len(tabela) < 1:
Expand All @@ -40,15 +55,16 @@ def parse(code, tabela):
ano1 = int(evento['data'].split('/')[2])
data1 = date(ano1, mes1, dia1)
delta = data1 - data0
delta_utils = networkdays(data0, data1)
except Exception:
delta = 0
delta_utils = 0
pass
#print(evento['tipo'], evento['status'])

data = evento['data'] + ' ' + evento['hora']
if delta.days == 1:
data = data + ' (' + str(delta.days) + ' dia)'
elif delta.days > 1:
data = data + ' (' + str(delta.days) + ' dias)'
data += parse_data(delta.days, delta_utils)

try:
local = evento['unidade']['local']
except Exception:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pytest-mock = "^3.6.1"
coverage = "^5.5"
pytest-cov = "^2.12.1"
pytest-asyncio = "^0.15.1"
workadays = "^2021.6.10"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down