-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
34 lines (26 loc) · 914 Bytes
/
Copy pathpython.py
File metadata and controls
34 lines (26 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""CFE API - Python example.
Requirements: requests (`pip install requests`).
"""
import os
import requests
API = "https://cfe-api.fly.dev"
API_KEY = os.environ["CFE_API_KEY"]
def consulta(rpu: str, nombre: str) -> dict:
r = requests.post(
f"{API}/api/v1/consulta",
headers={"X-API-Key": API_KEY},
json={"rpu": rpu, "nombre": nombre},
timeout=120,
)
r.raise_for_status()
return r.json()
def balance() -> dict:
r = requests.get(f"{API}/api/v1/balance", headers={"X-API-Key": API_KEY})
r.raise_for_status()
return r.json()
if __name__ == "__main__":
result = consulta("123456789012", "JUAN PEREZ")
data = result["data"]
print(f"Tarifa: {data['tarifa']} Anual: {data['annual_kwh']} kWh")
print(f"Hilos: {data.get('hilos') or 'no disponible'}")
print(f"Cobrado: {result['charged_cents']/100:.2f} MXN Cache: {result['cached']}")