att
This commit is contained in:
parent
3aaf089d8e
commit
db682de691
@ -6,7 +6,6 @@ import re
|
|||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import pyodbc
|
import pyodbc
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -14,10 +13,6 @@ hoje_coluna = datetime.today() # Pegando a Data e Hora de hoje
|
|||||||
hoje_formatado = hoje_coluna.strftime('%Y-%m-%d')
|
hoje_formatado = hoje_coluna.strftime('%Y-%m-%d')
|
||||||
data_atual = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
data_atual = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
# Constantes de tempo em segundos
|
|
||||||
TEMPO_ESPERA_SUCESSO = 45 * 60 # 45 minutos
|
|
||||||
TEMPO_ESPERA_ERRO = 3 * 60 # 3 minutos
|
|
||||||
|
|
||||||
def generate_code_verifier():
|
def generate_code_verifier():
|
||||||
"""Gera um code_verifier aleatório."""
|
"""Gera um code_verifier aleatório."""
|
||||||
return base64.urlsafe_b64encode(os.urandom(32)).decode('utf-8').rstrip("=")
|
return base64.urlsafe_b64encode(os.urandom(32)).decode('utf-8').rstrip("=")
|
||||||
@ -233,11 +228,10 @@ def insert_token_to_db(token):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Erro ao inserir token no banco de dados: {e}")
|
print(f"Erro ao inserir token no banco de dados: {e}")
|
||||||
|
|
||||||
def main_loop():
|
def main():
|
||||||
"""
|
"""
|
||||||
Função principal que executa em loop, controlando os tempos de espera
|
Função principal que executa uma única vez
|
||||||
"""
|
"""
|
||||||
while True:
|
|
||||||
try:
|
try:
|
||||||
print(f"\n[{datetime.now()}] Iniciando processo de obtenção do token...")
|
print(f"\n[{datetime.now()}] Iniciando processo de obtenção do token...")
|
||||||
|
|
||||||
@ -251,9 +245,7 @@ def main_loop():
|
|||||||
|
|
||||||
if not csrf_token or not state_properties:
|
if not csrf_token or not state_properties:
|
||||||
print(f"[{datetime.now()}] Falha ao extrair CSRF Token ou StateProperties.")
|
print(f"[{datetime.now()}] Falha ao extrair CSRF Token ou StateProperties.")
|
||||||
print(f"Aguardando {TEMPO_ESPERA_ERRO/60} minutos antes de tentar novamente...")
|
return
|
||||||
time.sleep(TEMPO_ESPERA_ERRO)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Dados de login
|
# Dados de login
|
||||||
username = "daniel.rodrigue"
|
username = "daniel.rodrigue"
|
||||||
@ -264,9 +256,7 @@ def main_loop():
|
|||||||
|
|
||||||
if not login_response:
|
if not login_response:
|
||||||
print(f"[{datetime.now()}] Falha no login.")
|
print(f"[{datetime.now()}] Falha no login.")
|
||||||
print(f"Aguardando {TEMPO_ESPERA_ERRO/60} minutos antes de tentar novamente...")
|
return
|
||||||
time.sleep(TEMPO_ESPERA_ERRO)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Enviar requisição final
|
# Enviar requisição final
|
||||||
final_page_html = send_final_request(session, csrf_token, state_properties)
|
final_page_html = send_final_request(session, csrf_token, state_properties)
|
||||||
@ -274,9 +264,7 @@ def main_loop():
|
|||||||
|
|
||||||
if not code:
|
if not code:
|
||||||
print(f"[{datetime.now()}] Falha ao extrair código.")
|
print(f"[{datetime.now()}] Falha ao extrair código.")
|
||||||
print(f"Aguardando {TEMPO_ESPERA_ERRO/60} minutos antes de tentar novamente...")
|
return
|
||||||
time.sleep(TEMPO_ESPERA_ERRO)
|
|
||||||
continue
|
|
||||||
|
|
||||||
token = send_token_request(code, code_verifier)
|
token = send_token_request(code, code_verifier)
|
||||||
tokens = extract_tokens_2(token)
|
tokens = extract_tokens_2(token)
|
||||||
@ -285,19 +273,13 @@ def main_loop():
|
|||||||
access_token = tokens["access_token"]
|
access_token = tokens["access_token"]
|
||||||
insert_token_to_db(access_token)
|
insert_token_to_db(access_token)
|
||||||
print(f"[{datetime.now()}] Token obtido e salvo com sucesso!")
|
print(f"[{datetime.now()}] Token obtido e salvo com sucesso!")
|
||||||
print(f"Aguardando {TEMPO_ESPERA_SUCESSO/60} minutos antes da próxima atualização...")
|
|
||||||
time.sleep(TEMPO_ESPERA_SUCESSO)
|
|
||||||
else:
|
else:
|
||||||
print(f"[{datetime.now()}] Falha ao processar tokens.")
|
print(f"[{datetime.now()}] Falha ao processar tokens.")
|
||||||
print(f"Aguardando {TEMPO_ESPERA_ERRO/60} minutos antes de tentar novamente...")
|
|
||||||
time.sleep(TEMPO_ESPERA_ERRO)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[{datetime.now()}] Erro inesperado: {str(e)}")
|
print(f"[{datetime.now()}] Erro inesperado: {str(e)}")
|
||||||
print(f"Aguardando {TEMPO_ESPERA_ERRO/60} minutos antes de tentar novamente...")
|
|
||||||
time.sleep(TEMPO_ESPERA_ERRO)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main_loop()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user