-
Notifications
You must be signed in to change notification settings - Fork 0
/
tachi.py
36 lines (28 loc) · 957 Bytes
/
tachi.py
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
from datetime import datetime
import requests
from requests import Response
from config import (
TACHI_BASE_URL,
TACHI_API_KEY,
TACHI_IMPORT_ENDPOINT,
TACHI_LATEST_SESSION_ENDPOINT,
)
def create_base(gpt: tuple[str, str]) -> dict:
return {
"meta": {"game": gpt[0], "playtype": gpt[1], "service": "flower-tachi"},
"scores": [],
}
def submit_score(json_data: dict) -> Response:
headers = {"Authorization": "Bearer " + TACHI_API_KEY}
return requests.post(
TACHI_BASE_URL + TACHI_IMPORT_ENDPOINT, json=json_data, headers=headers
)
def get_recent_session(ugpt: tuple[str, str]) -> datetime.date:
headers = {"Authorization": "Bearer " + TACHI_API_KEY}
res = requests.get(
TACHI_BASE_URL + TACHI_LATEST_SESSION_ENDPOINT.format("me", ugpt[0], ugpt[1]),
headers=headers,
)
if res.status_code != 200:
raise Exception("no session found")
return res.json()