triangle-api 0.1.2__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.2
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.2",
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
- # Esperamos a página estabilizar antes de recarregar
94
+ # Esperamos a página carregar o básico
96
95
  page.wait_for_load_state("domcontentloaded")
97
96
 
98
- with page.expect_response("**/retrieveAccount", timeout=30000) as resp:
99
- 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
+ """
100
109
 
101
- self.account_data = resp.value.json()
110
+ # Executa o fetch dentro do contexto do navegador
111
+ self.account_data = page.evaluate(js_get_account)
102
112
 
103
- # Salva os cookies/sessão somente após confirmar a captura dos dados
104
113
  if self.account_data:
114
+ # Agora que temos os dados, salvamos a sessão
105
115
  context.storage_state(path=self.session_path)
106
- 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.")
107
119
 
108
120
  except Exception as e:
109
- print(f"[AVISO] Não foi possível capturar os dados via rede: {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.2
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.2"
4
- __all__ = ["TriangleClient"]
File without changes
File without changes