triangle-api 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: triangle-api
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Unofficial Python wrapper for Canadian Tire Triangle Mastercard API
5
5
  Home-page: https://github.com/diogobas/triangle-api
6
6
  Author: Diogo Bastos
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="triangle-api", # Nome que aparecerá no PyPI
8
- version="0.1.3",
8
+ version="0.1.4",
9
9
  author="Diogo Bastos",
10
10
  author_email="seu-email@exemplo.com", # Opcional
11
11
  description="Unofficial Python wrapper for Canadian Tire Triangle Mastercard API",
@@ -0,0 +1,4 @@
1
+ from .client import TriangleClient
2
+
3
+ __version__ = "0.1.4"
4
+ __all__ = ["TriangleClient"]
@@ -88,25 +88,37 @@ class TriangleClient:
88
88
  browser.close()
89
89
  return None
90
90
 
91
- # 5. Captura Final de Dados (Saldo e transientReference)
92
- # Fazemos um reload forçado para "pescar" o JSON do saldo atualizado
91
+ # 5. CAPTURA FINAL DE DADOS (Saldo e transientReference)
93
92
  print("[API] Capturando dados financeiros (retrieveAccount)...")
94
93
  try:
95
- # Garantimos que a página está estável antes de pedir o saldo
96
- page.wait_for_load_state("networkidle", timeout=10000)
94
+ # Esperamos a página carregar o básico
95
+ page.wait_for_load_state("domcontentloaded")
97
96
 
98
- # Tentamos capturar a resposta disparando um reload limpo
99
- with page.expect_response("**/retrieveAccount", timeout=20000) as resp_info:
100
- page.goto("https://www.ctfs.com/content/dash/en/private/Summary.html")
97
+ # Em vez de 'esperar' uma resposta, nós 'pedimos' os dados
98
+ # Isso evita o erro de "Protocol error"
99
+ js_get_account = """
100
+ async () => {
101
+ const r = await fetch('/dash/v1/account/retrieveAccount', {
102
+ method: 'POST',
103
+ headers: { 'Content-Type': 'application/json' },
104
+ body: JSON.stringify({})
105
+ });
106
+ return r.ok ? await r.json() : null;
107
+ }
108
+ """
109
+
110
+ # Executa o fetch dentro do contexto do navegador
111
+ self.account_data = page.evaluate(js_get_account)
101
112
 
102
- self.account_data = resp_info.value.json()
103
113
  if self.account_data:
114
+ # Agora que temos os dados, salvamos a sessão
104
115
  context.storage_state(path=self.session_path)
105
- print("[API] Sessão e dados financeiros salvos.")
116
+ print("[API] Dados financeiros capturados com sucesso.")
117
+ else:
118
+ print("[AVISO] O servidor retornou vazio para o saldo.")
119
+
106
120
  except Exception as e:
107
- # Se falhar aqui, não quebramos o script, pois o get_transactions
108
- # vai tentar sincronizar novamente mais tarde.
109
- print(f"[AVISO] Falha temporária na captura do saldo: {e}")
121
+ print(f"[ERRO] Falha ao capturar saldo via JS: {e}")
110
122
 
111
123
  browser.close()
112
124
  return self.account_data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: triangle-api
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Unofficial Python wrapper for Canadian Tire Triangle Mastercard API
5
5
  Home-page: https://github.com/diogobas/triangle-api
6
6
  Author: Diogo Bastos
@@ -1,4 +0,0 @@
1
- from .client import TriangleClient
2
-
3
- __version__ = "0.1.3"
4
- __all__ = ["TriangleClient"]
File without changes
File without changes