Compare commits
10 Commits
a811302b1b
...
9beacb963c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9beacb963c | ||
|
|
afd9944403 | ||
|
|
822c7201a6 | ||
|
|
0ac2401d76 | ||
|
|
6ab543e099 | ||
|
|
3bc578263b | ||
|
|
e5c4ca46cf | ||
|
|
48a3886cb4 | ||
|
|
d097d7b5b9 | ||
|
|
292bc45582 |
@ -15,7 +15,7 @@ CONNECTION_STRING = (
|
||||
"SERVER=10.77.77.10;"
|
||||
"DATABASE=GINSENG;"
|
||||
"UID=supginseng;"
|
||||
"PWD=Iphone2513@;"
|
||||
"PWD=Ginseng@;"
|
||||
"PORT=1433;"
|
||||
"TrustServerCertificate=yes"
|
||||
)
|
||||
@ -427,6 +427,29 @@ def worker_inserir_banco(fila, conn_string, stats, stop_event):
|
||||
conn.close()
|
||||
|
||||
|
||||
def deletar_dados_existentes(data_venda):
|
||||
"""Deleta dados existentes para a data especificada antes de inserir novos"""
|
||||
try:
|
||||
conn = pyodbc.connect(CONNECTION_STRING)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Deletar da tabela principal (itens e pagamentos são deletados automaticamente pelo CASCADE)
|
||||
cursor.execute("DELETE FROM Grgb_sales_receipts WHERE sale_date = ?", data_venda)
|
||||
deleted_count = cursor.rowcount
|
||||
conn.commit()
|
||||
|
||||
if deleted_count > 0:
|
||||
print(f" 🗑️ Deletados: {deleted_count} registros existentes")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return deleted_count
|
||||
|
||||
except Exception as e:
|
||||
print(f" ⚠ Erro ao deletar dados existentes: {e}")
|
||||
return 0
|
||||
|
||||
|
||||
def processar_dia(data_venda, fila, stats):
|
||||
"""Processa um dia específico - busca da API e coloca na fila"""
|
||||
|
||||
@ -437,7 +460,12 @@ def processar_dia(data_venda, fila, stats):
|
||||
print(f" {data_venda}: Nenhum registro")
|
||||
return True # Sucesso, apenas não tem dados
|
||||
|
||||
print(f" {data_venda}: {total} registros, buscando...")
|
||||
print(f" {data_venda}: {total} registros encontrados na API")
|
||||
|
||||
# Deletar dados existentes para esta data antes de inserir os novos
|
||||
deletar_dados_existentes(data_venda)
|
||||
|
||||
print(f" {data_venda}: Buscando dados da API...")
|
||||
|
||||
# Calcular páginas
|
||||
paginas = list(range(0, total, PAGE_SIZE))
|
||||
@ -557,9 +585,10 @@ def processar_periodo(data_inicio_str, data_fim_str):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Configuração do período
|
||||
DATA_INICIO = "2025-09-24"
|
||||
DATA_FIM = datetime.now().strftime('%Y-%m-%d') # Hoje
|
||||
# Configuração do período - sempre pega o dia anterior (ontem)
|
||||
ONTEM = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
|
||||
DATA_INICIO = ONTEM
|
||||
DATA_FIM = ONTEM
|
||||
|
||||
# Permite passar datas como argumentos: python script.py 2025-09-24 2025-12-31
|
||||
if len(sys.argv) >= 3:
|
||||
|
||||
@ -71,7 +71,7 @@ def get_db_connection():
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
@ -39,7 +39,7 @@ DB_CONNECTION_STRING = (
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes;'
|
||||
'Encrypt=yes'
|
||||
|
||||
@ -37,9 +37,9 @@ store_codes = [
|
||||
"20991", "20992", "20993", "20994", "20995", "20996", "20997", "20998", "20999",
|
||||
"21000", "21001", "21068", "21277", "21278", "21296", "21375", "21381", "21383",
|
||||
"21495", "21624", "21647", "22541", "3546", "4560", "5699", "910173", "910291",
|
||||
"21007", "23665", "23712", "23705", "23711", "23704", "23707", "23702", "23703",
|
||||
"23713", "23708", "23706", "23701", "23709","23475","23156","14668", "24253",
|
||||
"24254", "24255", "24258", "24257", "24268", "24269", "24293", "23813", "24449", "24450", "24455", "24458"
|
||||
"21007", "23665", "23712", "23711", "23702", "23703",
|
||||
"23713", "23708", "23701", "23709","23475","23156","14668", "24253",
|
||||
"24254", "24255", "24258", "24257", "24268", "24269", "24293", "23813", "24449", "24450", "24455", "24458", "24454", "24447", "24448", "24451", "24456", "24457", "24453", "24452"
|
||||
]
|
||||
|
||||
# Mapeamento de códigos para nomes de categorias
|
||||
@ -133,7 +133,7 @@ conn = pyodbc.connect(
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
@ -47,19 +47,19 @@ HEADERS_API = {
|
||||
|
||||
# Configurações dos dois grupos de lojas
|
||||
LOJAS_GRUPO_1 = [
|
||||
"24268", "24258", "23701", "23702", "23705", "23706", "23665", "23709", "23708",
|
||||
"23713", "23707", "23156", "24254", "24253", "23813", "20056", "23475", "3546",
|
||||
"24268", "24258", "24454", "23702", "24455", "24450", "23665", "24448", "24447",
|
||||
"23713", "24449", "23156", "24254", "24253", "23813", "20056", "23475", "3546",
|
||||
"21647", "12824", "14617", "4560", "21068", "21277", "21296", "21381", "13427",
|
||||
"21624", "19103", "14668", "20006", "20057", "20005", "20009", "5699",
|
||||
"12522", "12817", "12820", "12829", "12818", "12823", "12826", "12828",
|
||||
"12830", "12838", "20441", "20858", "21007", "910173", "910291"
|
||||
"12830", "12838", "20441", "20858", "21007", "910173", "910291", "24455"
|
||||
]
|
||||
|
||||
LOJAS_GRUPO_2 = [
|
||||
"20992", "21383", "23704", "23703", "20986", "24293", "23712", "20994", "23711",
|
||||
"20992", "21383", "24458", "23703", "20986", "24293", "24451", "20994", "23711",
|
||||
"24269", "21000", "21001", "21375", "20970", "20989", "22541", "20988", "20993",
|
||||
"20999", "24255", "24257", "20991", "20969", "20998", "20996", "20997", "20995",
|
||||
"21495", "20968", "21278"
|
||||
"21495", "20968", "21278", "24458"
|
||||
]
|
||||
|
||||
|
||||
@ -291,7 +291,7 @@ def conectar_banco():
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
@ -326,7 +326,10 @@ def main():
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
actions = ActionChains(driver)
|
||||
actions.key_down(Keys.CONTROL).send_keys('k').key_up(Keys.CONTROL).perform()
|
||||
time.sleep(1)
|
||||
|
||||
# Aguardar a página carregar completamente
|
||||
print("Aguardando 10 segundos para a página carregar...")
|
||||
time.sleep(10)
|
||||
|
||||
# Apertar TAB 3 vezes
|
||||
print("Apertando TAB 3 vezes...")
|
||||
@ -604,7 +607,7 @@ def main():
|
||||
f'SERVER=10.77.77.10;'
|
||||
f'DATABASE=GINSENG;'
|
||||
f'UID=supginseng;'
|
||||
f'PWD=Iphone2513@;'
|
||||
f'PWD=Ginseng@;'
|
||||
f'PORT=1433;'
|
||||
f'TrustServerCertificate=yes;'
|
||||
f'Encrypt=yes'
|
||||
|
||||
@ -200,7 +200,7 @@ def insert_token_to_db(token):
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
@ -9,7 +9,7 @@ DB_CONNECTION_STRING = (
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
@ -32,7 +32,7 @@ class RGBFiscalInvoicesExtractor:
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes;'
|
||||
'Encrypt=yes'
|
||||
|
||||
@ -14,7 +14,7 @@ DB_CONNECTION_STRING = (
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
@ -328,7 +328,7 @@ class BoticarioAPI:
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes;'
|
||||
'Encrypt=yes'
|
||||
@ -352,7 +352,7 @@ class BoticarioAPI:
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433'
|
||||
)
|
||||
|
||||
@ -1174,7 +1174,7 @@ def get_bearer_token_from_database():
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes;'
|
||||
'Encrypt=yes'
|
||||
@ -1211,7 +1211,7 @@ def get_bearer_token_from_database():
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433'
|
||||
)
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ class RGBTokenClient:
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes;'
|
||||
'Encrypt=yes'
|
||||
|
||||
@ -277,7 +277,7 @@ def get_db_connection():
|
||||
'SERVER=10.77.77.10;'
|
||||
'DATABASE=GINSENG;'
|
||||
'UID=supginseng;'
|
||||
'PWD=Iphone2513@;'
|
||||
'PWD=Ginseng@;'
|
||||
'PORT=1433;'
|
||||
'TrustServerCertificate=yes'
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user