Created
April 21, 2018 20:06
-
-
Save rougeth/ae171c106be46791233fbb17ec6a61de to your computer and use it in GitHub Desktop.
Async que se faz - TDC 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Código usado na palestra "Async que se faz - asyncio na prática" | |
# no TDC 2018 em Florianópolis | |
# Creative Commons Attribution 4.0 International license <https://creativecommons.org/licenses/by/4.0/> | |
import random | |
from time import sleep | |
from utils import UPDATE_AVG, sync_request | |
def buscar_pedidos_no_banco(): | |
print('- Buscar pedidos no banco') | |
return range(18000) | |
def checar_pedido_no_correios(pedido): | |
sync_request(pedido, 'Correios') | |
def atualizar_pacote_no_banco(pedido): | |
print('- {}: Atualiza pacote'.format(pedido)) | |
def notificar_usuario(pedido): | |
sync_request(pedido, 'Telegram') | |
def main(): | |
pedidos = buscar_pedidos_no_banco() | |
for pedido in pedidos: | |
checar_pedido_no_correios(pedido) | |
if random.choice(UPDATE_AVG): | |
atualizar_pacote_no_banco(pedido) | |
notificar_usuario(pedido) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment