-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathother.py
More file actions
44 lines (35 loc) · 1.45 KB
/
other.py
File metadata and controls
44 lines (35 loc) · 1.45 KB
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
35
36
37
38
39
40
41
42
43
44
import os, requests
HOST = "sofascore.p.rapidapi.com"
BASE_URL = f"https://{HOST}"
HEADERS = {
"x-rapidapi-host": HOST,
"x-rapidapi-key": os.getenv("RAPIDAPI_KEY", "ac07569428mshc51ad594e33debcp15f460jsn2e6cb9ab7fa6")
}
def try_endpoint(path, params):
url = f"{BASE_URL}/{path}"
r = requests.get(url, headers=HEADERS, params=params, timeout=20)
# 204 = ok mais rien
if r.status_code == 204:
return (path, r.status_code, "NO_CONTENT", None)
try:
data = r.json()
except Exception:
return (path, r.status_code, "NOT_JSON", r.text[:200])
# erreur dans le body
if isinstance(data, dict) and "error" in data:
return (path, r.status_code, "API_ERROR", data["error"])
keys = list(data.keys()) if isinstance(data, dict) else type(data).__name__
return (path, r.status_code, "OK", keys)
# ⚠️ Mets un event_id réel (un match) -> tu peux le prendre depuis tes events "next matches"
EVENT_ID = 0 # <-- remplace par un vrai id de match (ex: df.iloc[0]["event_id"])
candidates = [
("events/get-odds", {"eventId": str(EVENT_ID)}),
("events/get-event-odds", {"eventId": str(EVENT_ID)}),
("events/get-markets", {"eventId": str(EVENT_ID)}),
("events/get-betting-odds", {"eventId": str(EVENT_ID)}),
("odds/get-odds", {"eventId": str(EVENT_ID)}),
("bookmakers/get-odds", {"eventId": str(EVENT_ID)}),
]
for path, params in candidates:
res = try_endpoint(path, params)
print(res)