diff --git a/enrich_paytype_backfill.py b/enrich_paytype_backfill.py new file mode 100644 index 0000000..131e0b1 --- /dev/null +++ b/enrich_paytype_backfill.py @@ -0,0 +1,152 @@ +""" +Backfill de paymentType para todos os Numero_Pedido em Grgb_vendas_report +que ainda não constam em Grgb_installment_paytype. + +Pode ser interrompido e re-executado a qualquer momento — retoma de onde parou. +""" +import re +import time +import requests +from typing import Optional + +from installments_reader import Auth, get_installments_page + +# ─── CONFIG ─────────────────────────────────────────────────────────────────── +SQL_CONN = ( + "DRIVER={ODBC Driver 17 for SQL Server};" + "SERVER=10.77.77.10;" + "DATABASE=GINSENG;" + "UID=andrey;" + "PWD=88253332;" + "TrustServerCertificate=yes;" +) + +INSTALLMENT_GROUP_COL = "Numero_Pedido" +RATE_LIMIT_S = 1.5 +PRINT_EVERY = 1 +# ────────────────────────────────────────────────────────────────────────────── + + +def _conn_str() -> str: + s = SQL_CONN.rstrip(";") + if not re.search(r"(?i)\bEncrypt\b", s): + s += ";Encrypt=no" + return s + ";" + + +def _ensure_paytype_table(cur) -> None: + cur.execute(""" +IF OBJECT_ID('dbo.Grgb_installment_paytype', 'U') IS NULL +BEGIN + CREATE TABLE dbo.Grgb_installment_paytype ( + InstallmentGroupCode VARCHAR(50) NOT NULL PRIMARY KEY, + PaymentType VARCHAR(80) NULL, + ConsultadoEm DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME() + ) +END +""") + + +def _load_pending(cur) -> list[str]: + cur.execute(f""" +SELECT DISTINCT [{INSTALLMENT_GROUP_COL}] +FROM dbo.Grgb_vendas_report +WHERE [{INSTALLMENT_GROUP_COL}] IS NOT NULL + AND [{INSTALLMENT_GROUP_COL}] <> '' + AND [{INSTALLMENT_GROUP_COL}] NOT IN ( + SELECT InstallmentGroupCode FROM dbo.Grgb_installment_paytype + ) +ORDER BY [{INSTALLMENT_GROUP_COL}] +""") + return [str(r[0]) for r in cur.fetchall()] + + +def _query_payment_type( + session: requests.Session, + auth: Auth, + group_code: str, +) -> Optional[str]: + """Usa get_installments_page do installments_reader (headers + retry corretos).""" + try: + body = get_installments_page( + session=session, + auth=auth, + start_date=None, + end_date=None, + installment_change=None, + mediator_code=None, + page=1, + installment_group_code=group_code, + ) + installments = body.get("data", {}).get("installments") or [] + if installments: + return str(installments[0].get("paymentType") or "") + except Exception as exc: + print(f"[erro] groupCode={group_code}: {exc}") + return None + + +def _save(cur, group_code: str, payment_type: Optional[str]) -> None: + cur.execute( + "INSERT INTO dbo.Grgb_installment_paytype (InstallmentGroupCode, PaymentType) " + "VALUES (?, ?)", + group_code, payment_type, + ) + + +def main() -> None: + import pyodbc + + conn_str = _conn_str() + + cn = pyodbc.connect(conn_str, timeout=60) + cn.autocommit = False + cur = cn.cursor() + _ensure_paytype_table(cur) + cn.commit() + pending = _load_pending(cur) + cur.close(); cn.close() + + total = len(pending) + print(f"[backfill] {total} pedidos pendentes de paymentType") + if not total: + print("[backfill] nada a fazer.") + return + + session = requests.Session() + session.trust_env = False + auth = Auth(session) + + ok = erros = 0 + for i, group_code in enumerate(pending, 1): + payment_type = _query_payment_type(session, auth, group_code) + + cn = pyodbc.connect(conn_str, timeout=60) + cn.autocommit = False + cur = cn.cursor() + try: + _save(cur, group_code, payment_type) + cn.commit() + ok += 1 + except Exception as exc: + cn.rollback() + print(f"[erro] sql groupCode={group_code}: {exc}") + erros += 1 + finally: + cur.close(); cn.close() + + if i % PRINT_EVERY == 0 or i == total: + pct = i / total * 100 + print( + f"[backfill] {i}/{total} ({pct:.1f}%)" + f" ok={ok} erros={erros}" + f" ultimo={group_code} paymentType={payment_type}" + ) + + time.sleep(RATE_LIMIT_S) + + print(f"\n[backfill] concluido: {ok} gravados, {erros} erros") + + +if __name__ == "__main__": + main() diff --git a/recebiveis_report_importer.py b/recebiveis_report_importer.py index 1abb8df..2d4d7d2 100644 --- a/recebiveis_report_importer.py +++ b/recebiveis_report_importer.py @@ -57,6 +57,12 @@ WRITE_SQL = True _SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) WATERMARK_FILE = os.path.join(_SCRIPT_DIR, "vendas_watermark.json") IMPORT_BATCH_SIZE = 500 # linhas por lote no SQL Server + +ENRICH_PAYMENT_TYPES = True # True = consulta API de parcelas para preencher paymentType +# Nome da coluna em Grgb_vendas_report que contém o installmentGroupCode. +# Verifique rodando: SELECT TOP 1 * FROM dbo.Grgb_vendas_report +INSTALLMENT_GROUP_COL = "Numero_Pedido" +ENRICH_RATE_LIMIT_S = 0.3 # pausa entre chamadas à API de parcelas # ────────────────────────────────────────────────────────────────────────────── SQL_CONN = ( @@ -72,6 +78,10 @@ REPORTS_URL = ( "https://bff-portal-apigw.produto-financeiro.grupoboticario.digital" "/v2/franchisee/reports" ) +INSTALLMENTS_URL = ( + "https://bff-credit-container-portal-apigw.prd.produto-financeiro.app.grupoboticario.com.br" + "/v1/franchisee/installments" +) _DONE_STATUSES = {"generated", "generated_csv", "done", "completed", "ready", "available"} _FAIL_STATUSES = {"failed", "error", "erro", "falha"} @@ -461,6 +471,125 @@ VALUES (?, ?, ?, ?) return inserted +# ─── ENRIQUECIMENTO paymentType ─────────────────────────────────────────────── + +def _ensure_paytype_table(cur) -> None: + cur.execute(""" +IF OBJECT_ID('dbo.Grgb_installment_paytype', 'U') IS NULL +BEGIN + CREATE TABLE dbo.Grgb_installment_paytype ( + InstallmentGroupCode VARCHAR(50) NOT NULL PRIMARY KEY, + PaymentType VARCHAR(80) NULL, + ConsultadoEm DATETIME2 NOT NULL DEFAULT SYSUTCDATETIME() + ) +END +""") + + +def _fetch_pending_group_codes(cur, col_name: str, file_name: str) -> list[str]: + """Retorna installmentGroupCodes do arquivo atual que ainda não têm paymentType.""" + cur.execute(f""" +SELECT DISTINCT [{col_name}] +FROM dbo.Grgb_vendas_report +WHERE NomeArquivo = ? + AND [{col_name}] IS NOT NULL + AND [{col_name}] <> '' + AND [{col_name}] NOT IN ( + SELECT InstallmentGroupCode FROM dbo.Grgb_installment_paytype + ) +""", file_name) + return [str(r[0]) for r in cur.fetchall()] + + +def _query_payment_type( + session: requests.Session, + auth: Auth, + group_code: str, +) -> Optional[str]: + """Consulta a API de parcelas e retorna o paymentType da primeira parcela.""" + try: + r = session.get( + INSTALLMENTS_URL, + params={"installmentGroupCode": group_code, "page": 1}, + headers=_headers(auth), + timeout=30, + ) + if not r.ok: + print(f"[enrich] {r.status_code} para groupCode={group_code}") + return None + installments = r.json().get("data", {}).get("installments") or [] + if installments: + return str(installments[0].get("paymentType") or "") + except Exception as exc: + print(f"[enrich] erro ao consultar groupCode={group_code}: {exc}") + return None + + +def enrich_payment_types(session: requests.Session, auth: Auth, file_name: str) -> None: + """ + Para cada installmentGroupCode do arquivo atual que ainda não consta + em Grgb_installment_paytype, consulta a API e persiste o paymentType. + """ + import pyodbc + + conn_str = _sql_conn_str() + + cn = pyodbc.connect(conn_str, timeout=60) + cn.autocommit = False + cur = cn.cursor() + _ensure_paytype_table(cur) + cn.commit() + + # verifica se a coluna configurada existe na tabela de dados + cur.execute(""" +SELECT LOWER(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS +WHERE TABLE_SCHEMA='dbo' AND TABLE_NAME='Grgb_vendas_report' +""") + existing_cols = {r[0] for r in cur.fetchall()} + col_name = INSTALLMENT_GROUP_COL + if col_name.lower() not in existing_cols: + print( + f"[enrich] coluna '{col_name}' nao encontrada em Grgb_vendas_report. " + f"Ajuste INSTALLMENT_GROUP_COL. Colunas disponiveis: {sorted(existing_cols)}" + ) + cur.close(); cn.close() + return + + pending = _fetch_pending_group_codes(cur, col_name, file_name) + cur.close(); cn.close() + + total = len(pending) + print(f"[enrich] {total} installmentGroupCode(s) para consultar") + if not total: + return + + for i, group_code in enumerate(pending, 1): + payment_type = _query_payment_type(session, auth, group_code) + + cn = pyodbc.connect(conn_str, timeout=60) + cn.autocommit = False + cur = cn.cursor() + try: + cur.execute( + "INSERT INTO dbo.Grgb_installment_paytype (InstallmentGroupCode, PaymentType) " + "VALUES (?, ?)", + group_code, payment_type, + ) + cn.commit() + except Exception: + cn.rollback() + raise + finally: + cur.close(); cn.close() + + if i % 50 == 0 or i == total: + print(f"[enrich] {i}/{total} ultimo={group_code} paymentType={payment_type}") + + time.sleep(ENRICH_RATE_LIMIT_S) + + print(f"[enrich] concluido: {total} registros gravados em Grgb_installment_paytype") + + # ─── MAIN ───────────────────────────────────────────────────────────────────── def _resolve_date_range() -> tuple[str, str]: @@ -544,6 +673,9 @@ def main() -> None: else: n = _import_csv(rows, csv_cols, file_name, chunk_start, chunk_end) total_linhas += n + if ENRICH_PAYMENT_TYPES and n > 0: + print(f"[enrich] enriquecendo paymentType para arquivo {file_name}...") + enrich_payment_types(session, auth, file_name) if INCREMENTAL: _save_watermark(chunk_end) diff --git a/test_installment.py b/test_installment.py new file mode 100644 index 0000000..fe86eb8 --- /dev/null +++ b/test_installment.py @@ -0,0 +1,1045 @@ +""" +Teste manual: digita um Numero_Pedido e consulta o paymentType na API. +""" +import requests +from installments_reader import Auth, get_installments_page + + +def main() -> None: + session = requests.Session() + session.trust_env = False + auth = Auth(session) + + # ── troque o valor abaixo para testar ── + codigos = [ + '488897167', + '488900751', + '489046144', +'489068635', +'489068635', +'489182708', +'489182708', +'489176675', +'489176675', +'489287708', +'489287708', +'489302682', +'489302682', +'489304522', +'489304522', +'489416528', +'489416528', +'489469622', +'489469622', +'489504266', +'489504266', +'489569575', +'489569575', +'489650051', +'489650051', +'489650916', +'489650916', +'489558752', +'489558752', +'489613544', +'489613544', +'489770485', +'489770485', +'489833835', +'489833835', +'489859925', +'489859925', +'489866953', +'489866953', +'489976274', +'489976274', +'489976566', +'489976566', +'490028441', +'490028441', +'489994132', +'489994132', +'490115712', +'490115712', +'490158554', +'490158554', +'490182408', +'490182408', +'490310969', +'490310969', +'490290148', +'490290148', +'490364961', +'490364961', +'490468502', +'490468502', +'490412991', +'490412991', +'490377513', +'490377513', +'490449347', +'490449347', +'490578607', +'490578607', +'490586602', +'490586602', +'490615182', +'490615182', +'490636921', +'490636921', +'490767854', +'490767854', +'490821622', +'490821622', +'490730454', +'490730454', +'490796778', +'490796778', +'490786154', +'490786154', +'488832795', +'488832795', +'488844457', +'488844457', +'488840876', +'488840876', +'488849098', +'488849098', +'488832688', +'488832688', +'488809343', +'488809343', +'488819937', +'488819937', +'488838155', +'488838155', +'488877308', +'488877308', +'488869375', +'488869375', +'488871171', +'488871171', +'488837494', +'488837494', +'488910189', +'488910189', +'488918937', +'488918937', +'488948287', +'488948287', +'488951131', +'488951131', +'488951733', +'488951733', +'488952602', +'488952602', +'488954098', +'488954098', +'488955447', +'488955447', +'488934039', +'488934039', +'488893798', +'488893798', +'488957552', +'488957552', +'488945349', +'488945349', +'488971901', +'488971901', +'488978793', +'488978793', +'488991246', +'488991246', +'488981985', +'488981985', +'489115478', +'489115478', +'489150599', +'489150599', +'489124360', +'489124360', +'489102571', +'489102571', +'489204623', +'489204623', +'489168018', +'489168018', +'489218340', +'489218340', +'489193775', +'489193775', +'489053190', +'489053190', +'489174079', +'489174079', +'489227990', +'489227990', +'489258514', +'489258514', +'489276471', +'489276471', +'489174767', +'489174767', +'489173480', +'489173480', +'489229122', +'489229122', +'489099356', +'489099356', +'489350877', +'489350877', +'489353647', +'489353647', +'489379264', +'489379264', +'489367879', +'489367879', +'489279195', +'489279195', +'489389477', +'489389477', +'489405101', +'489405101', +'489406153', +'489406153', +'489377734', +'489377734', +'489483968', +'489483968', +'489501177', +'489501177', +'489461542', +'489461542', +'489515886', +'489515886', +'489443577', +'489443577', +'489286734', +'489286734', +'489532352', +'489532352', +'489383427', +'489383427', +'489394568', +'489394568', +'489541936', +'489541936', +'489429744', +'489429744', +'489563444', +'489563444', +'489569024', +'489569024', +'489512070', +'489512070', +'489462988', +'489462988', +'489587081', +'489587081', +'489461274', +'489461274', +'489047492', +'489047492', +'489597627', +'489597627', +'489504102', +'489504102', +'489568205', +'489568205', +'489604339', +'489604339', +'489660616', +'489660616', +'489638892', +'489638892', +'489672383', +'489672383', +'489681679', +'489681679', +'489564847', +'489564847', +'489697391', +'489697391', +'489579518', +'489579518', +'489617874', +'489617874', +'489484025', +'489484025', +'489583883', +'489583883', +'489714125', +'489714125', +'489717894', +'489717894', +'489468239', +'489468239', +'489627988', +'489627988', +'489370097', +'489370097', +'489725709', +'489725709', +'489597728', +'489597728', +'489832626', +'489832626', +'489683678', +'489683678', +'489828935', +'489828935', +'489794823', +'489794823', +'489815685', +'489815685', +'489305306', +'489305306', +'489839132', +'489839132', +'489836311', +'489836311', +'489902136', +'489902136', +'489904417', +'489904417', +'489805498', +'489805498', +'489807613', +'489807613', +'489749932', +'489749932', +'489825423', +'489825423', +'489869731', +'489869731', +'489935510', +'489935510', +'489870051', +'489870051', +'489916407', +'489916407', +'489968301', +'489968301', +'490009269', +'490009269', +'489958607', +'489958607', +'490022611', +'490022611', +'490027889', +'490027889', +'489424918', +'489424918', +'490122064', +'490122064', +'489864977', +'489864977', +'489876193', +'489876193', +'489895530', +'489895530', +'490135701', +'490135701', +'489931466', +'489931466', +'489969305', +'489969305', +'490151941', +'490151941', +'489981333', +'489981333', +'490168091', +'490168091', +'490170344', +'490170344', +'489517623', +'489517623', +'490178089', +'490178089', +'490186647', +'490186647', +'490100807', +'490100807', +'490102254', +'490102254', +'490166532', +'490166532', +'490065410', +'490065410', +'490223525', +'490223525', +'490168722', +'490168722', +'490232543', +'490232543', +'490241513', +'490241513', +'490115167', +'490115167', +'490170975', +'490170975', +'490246221', +'490246221', +'490139487', +'490139487', +'490275325', +'490275325', +'490211095', +'490211095', +'490214240', +'490214240', +'490227265', +'490227265', +'490244136', +'490244136', +'490256520', +'490256520', +'490325729', +'490325729', +'490329448', +'490329448', +'490147256', +'490147256', +'490304214', +'490304214', +'490341193', +'490341193', +'490344662', +'490344662', +'490277018', +'490277018', +'490299624', +'490299624', +'490376613', +'490376613', +'490383021', +'490383021', +'490385566', +'490385566', +'490396628', +'490396628', +'490385689', +'490385689', +'490402005', +'490402005', +'490232196', +'490232196', +'490300785', +'490300785', +'490456319', +'490456319', +'490364772', +'490364772', +'490487581', +'490487581', +'490395721', +'490395721', +'490513951', +'490513951', +'490517955', +'490517955', +'490491484', +'490491484', +'490429140', +'490429140', +'490489726', +'490489726', +'490548409', +'490548409', +'490579931', +'490579931', +'490572638', +'490572638', +'490586386', +'490586386', +'490334619', +'490334619', +'490517727', +'490517727', +'490613404', +'490613404', +'490692411', +'490692411', +'490561010', +'490561010', +'490666985', +'490666985', +'490729602', +'490729602', +'490724654', +'490724654', +'490708235', +'490708235', +'490765453', +'490765453', +'490740205', +'490740205', +'490667361', +'490667361', +'490701466', +'490701466', +'490798923', +'490798923', +'490806229', +'490806229', +'490766676', +'490766676', +'490407567', +'490407567', +'490816837', +'490816837', +'490745937', +'490745937', +'490754960', +'490754960', +'490778775', +'490778775', +'490810815', +'490810815', +'490840568', +'490840568', +'490688153', +'490688153', +'490726267', +'490726267', +'490691898', +'490691898', +'490725653', +'490725653', +'490012216', +'490012216', +'488859494', +'488859494', +'488824857', +'488824857', +'488825162', +'488825162', +'488876914', +'488876914', +'488949239', +'488949239', +'488926843', +'488926843', +'488927119', +'488927119', +'488947467', +'488947467', +'488957390', +'488957390', +'489080787', +'489080787', +'489101687', +'489101687', +'489001560', +'489001560', +'489081505', +'489081505', +'489172160', +'489172160', +'489473637', +'489473637', +'489246344', +'489246344', +'489455459', +'489455459', +'489405041', +'489405041', +'489481801', +'489481801', +'489504996', +'489504996', +'489447686', +'489447686', +'489392926', +'489392926', +'489457037', +'489457037', +'489108743', +'489108743', +'489543566', +'489543566', +'489556971', +'489556971', +'489696822', +'489696822', +'489717549', +'489717549', +'489653913', +'489653913', +'489764781', +'489764781', +'489816454', +'489816454', +'489722596', +'489722596', +'490007201', +'490007201', +'490020898', +'490020898', +'490133032', +'490133032', +'489922866', +'489922866', +'490187003', +'490187003', +'490294269', +'490294269', +'490255562', +'490255562', +'490272248', +'490272248', +'490375398', +'490375398', +'489649804', +'489649804', +'490456579', +'490456579', +'490461583', +'490461583', +'490508291', +'490508291', +'490447494', +'490447494', +'490451683', +'490451683', +'490533536', +'490533536', +'490370631', +'490370631', +'490552756', +'490552756', +'490571115', +'490571115', +'490468814', +'490468814', +'490507594', +'490507594', +'490713077', +'490713077', +'490646556', +'490646556', +'490547756', +'490547756', +'490791993', +'490791993', +'490788921', +'490788921', +'490622836', +'490622836', +'488832697', +'488832697', +'488830110', +'488830110', +'488887190', +'488887190', +'488872641', +'488872641', +'488944800', +'488944800', +'489044879', +'489044879', +'489001990', +'489001990', +'489106945', +'489106945', +'488976791', +'488976791', +'489048241', +'489048241', +'489111894', +'489111894', +'489224155', +'489224155', +'489144704', +'489144704', +'489163154', +'489163154', +'489222239', +'489222239', +'489270950', +'489270950', +'489310802', +'489310802', +'489410388', +'489410388', +'489426600', +'489426600', +'489428833', +'489428833', +'489459101', +'489459101', +'489567904', +'489567904', +'489521037', +'489521037', +'489481576', +'489481576', +'489482463', +'489482463', +'489458451', +'489458451', +'489771029', +'489771029', +'489993460', +'489993460', +'489987792', +'489987792', +'490072042', +'490072042', +'490143505', +'490143505', +'490225942', +'490225942', +'490294807', +'490294807', +'490252170', +'490252170', +'490284387', +'490284387', +'490308775', +'490308775', +'490292066', +'490292066', +'490334466', +'490334466', +'490316126', +'490316126', +'490444414', +'490444414', +'490511013', +'490511013', +'490525310', +'490525310', +'490528299', +'490528299', +'490529408', +'490529408', +'490585358', +'490585358', +'490675100', +'490675100', +'490585046', +'490585046', +'490568370', +'490568370', +'490661679', +'490661679', +'490663777', +'490663777', +'490667174', +'490667174', +'490630814', +'490630814', +'490647115', +'490647115', +'490629448', +'490629448', +'490702446', +'490702446', +'490704007', +'490704007', +'490710089', +'490710089', +'490834889', +'490834889', +'490720824', +'490720824', +'489928621', +'489928621', +'489928621', +'489928621', +'488835445', +'488835445', +'488843239', +'488843239', +'488848524', +'488848524', +'488811116', +'488811116', +'488879604', +'488879604', +'488849941', +'488849941', +'488946022', +'488946022', +'488963960', +'488963960', +'489001997', +'489001997', +'488980316', +'488980316', +'489016201', +'489016201', +'489088097', +'489088097', +'489039411', +'489039411', +'489113265', +'489113265', +'488971870', +'488971870', +'489017205', +'489017205', +'489067343', +'489067343', +'488956960', +'488956960', +'489144659', +'489144659', +'488940394', +'488940394', +'489009800', +'489009800', +'489085609', +'489085609', +'489125944', +'489125944', +'489081097', +'489081097', +'489122266', +'489122266', +'489185975', +'489185975', +'489129206', +'489129206', +'489144808', +'489144808', +'489185174', +'489185174', +'489197067', +'489197067', +'489200334', +'489200334', +'489189515', +'489189515', +'489165068', +'489165068', +'489156720', +'489156720', +'489134779', +'489134779', +'489030453', +'489030453', +'489197030', +'489197030', +'489055479', +'489055479', +'489172163', +'489172163', +'489277761', +'489277761', +'489298878', +'489298878', +'489307023', +'489307023', +'489315633', +'489315633', +'489250616', +'489250616', +'489326716', +'489326716', +'489198570', +'489198570', +'489304192', +'489304192', +'489305116', +'489305116', +'489287417', +'489287417', +'489327952', +'489327952', +'489396128', +'489396128', +'489246610', +'489246610', +'489310979', +'489310979', +'489416517', +'489416517', +'489417717', +'489417717', +'489330583', +'489330583', +'489478760', +'489478760', +'489479941', +'489479941', +'489405600', +'489405600', +'489488216', +'489488216', +'489326059', +'489326059', +'489088128', +'489088128', +'489334406', +'489334406', +'489481213', +'489481213', +'489483570', +'489483570', +'489484003', +'489484003', +'489487711', +'489487711', +'489432072', +'489432072', +'489520497', +'489520497', +'489471005', +'489471005', +'489473472', +'489473472', +'489483896', +'489483896', +'489560560', +'489560560', +'489563135', +'489563135', +'489572950', +'489572950', +'489547813', +'489547813', +'489525280', +'489525280', +'489591705', +'489591705', +'489650526', +'489650526', +'489679159', +'489679159', +'489682118', +'489682118', +'489683434', +'489683434', +'489683659', +'489683659', +'489363507', +'489363507', +'489622498', +'489622498', +'489675489', +'489675489', +'489632644', +'489632644', +'489675063', +'489675063', +'489680657', +'489680657', +'489343097', +'489343097', +'489749848', +'489749848', +'489773388', +'489773388', +'489844566', +'489844566', +'489857669', +'489857669', +'489840363', +'489840363', +'489856550', +'489856550', +'489872983', +'489872983', +'489879366', +'489879366', +'489815124', +'489815124', +'489785271', +'489785271', +'489904518', +'489904518', +'489808211', +'489808211', +'489924670', +'489924670', +'489940910', +'489940910', +'489452669', +'489452669', +'489882482', +'489882482', +'489983646', +'489983646', +'489985985', +'489985985', +'489952858', +'489952858', +'490020540', +'490020540', +'490025166', +'490025166', +'490014493', +'490014493', +'490020570', +'490020570', +'490030627', +'490030627', +'490128389', +'490128389', +'490132593', +'490132593', +'489958498', +'489958498', +'490140271', +'490140271', +'489979295', +'489979295', +'490091894', +'490091894', +'490195656', +'490195656', +'489685871', +'489685871', +'490203496', +'490203496', +'490214534', +'490214534', +'489185302', +'489185302', +'490224264', +'490224264', +'490202966', +'490202966', +'489879144', +'489879144', +'490291870', +'490291870', +'490185439', +'490185439' + + ] + + for group_code in codigos: + + print(f"Consultando {group_code}...") + try: + body = get_installments_page( + session=session, + auth=auth, + start_date=None, + end_date=None, + installment_change=None, + mediator_code=None, + page=1, + installment_group_code=group_code, + ) + installments = body.get("data", {}).get("installments") or [] + if not installments: + print(" Nenhuma parcela encontrada.") + else: + for p in installments: + print( + f" parcela {p.get('installmentNumber')} " + f"paymentType={p.get('paymentType')} " + f"vencimento={p.get('dueDate')} " + f"valor={p.get('originalAmount')}" + ) + except Exception as exc: + print(f" Erro: {exc}") + + +if __name__ == "__main__": + main() diff --git a/vendas_watermark.json b/vendas_watermark.json new file mode 100644 index 0000000..31ff927 --- /dev/null +++ b/vendas_watermark.json @@ -0,0 +1 @@ +{"last_end_date": "2026-05-24"} \ No newline at end of file