diff options
| author | Andrew <saintruler@gmail.com> | 2020-02-11 22:52:36 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2020-02-11 22:52:36 +0400 |
| commit | 7b4099a416cdcfe6f253b72a26741203b6926929 (patch) | |
| tree | 9e2f66c70f463c3d9aa0d5901e6df74eaeb4637b /backend_api.py | |
| parent | bc2124fbfa33b0aa5969c86523afb4f404e21ee5 (diff) | |
Added binding to attempts API and integrated it into bot.
Diffstat (limited to 'backend_api.py')
| -rw-r--r-- | backend_api.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/backend_api.py b/backend_api.py index 8f678bb..e830609 100644 --- a/backend_api.py +++ b/backend_api.py @@ -75,3 +75,21 @@ def save_state(last_state: int, tg_id: int, user_data: dict) -> Tuple[int, Dict] def get_state(tg_id: int) -> Tuple[int, dict]: logger.debug(f"Trying to get state for user with id={tg_id}") return get_request(f"{BACKEND_URL}/api/state/get/{tg_id}/") + + +def create_attempt(tg_id: int, task_title: str, answer: str): + return post_request(f"{BACKEND_URL}/attempts/", data={ + "profile": json.dumps({"tg_id": tg_id}), + "task": json.dumps({"title": task_title}), + "answer": answer + }) + + +def get_attempts(tg_id: int=None, task_title: str=None): + data = {} + if tg_id is not None: + data["tg_id"] = tg_id + if task_title is not None: + data["task_title"] = task_title + + return get_request(f"{BACKEND_URL}/api/attempts/", data=data) |