From 99da20c9db94758179a59acdc8fe5e222335a6b5 Mon Sep 17 00:00:00 2001 From: Sam Rachmil-Etter Date: Sun, 15 Sep 2024 14:36:55 -0500 Subject: [PATCH 1/4] add /api/timeline endpoint --- berserk/clients/account.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/berserk/clients/account.py b/berserk/clients/account.py index 434785b..a5cd8b9 100644 --- a/berserk/clients/account.py +++ b/berserk/clients/account.py @@ -1,10 +1,12 @@ from __future__ import annotations -from typing import cast +from typing import Any, cast, Dict from .. import models from ..types.account import AccountInformation, Preferences from .base import BaseClient +from ..formats import LIJSON +from ..session import Params class Account(BaseClient): @@ -60,3 +62,15 @@ def upgrade_to_bot(self): """ path = "/api/bot/account/upgrade" self._r.post(path) + + def get_timeline(self, since: int = 1356998400070, nb: int = 15) -> Dict[str, Any]: + """Get your timeline events. + + :param int since: timestamp to show events since, default 1356998400070 + :param int nb: max number of events to fetch, default 15 + :return: timeline events of the authenticated user + """ + path = "/api/timeline" + params: Params = {"since": since, "nb": nb} + + return self._r.get(path, fmt=LIJSON, params=params) From ad213d9892bd65cc4788944b70288d148fea425a Mon Sep 17 00:00:00 2001 From: Sam Rachmil-Etter Date: Sun, 15 Sep 2024 14:45:03 -0500 Subject: [PATCH 2/4] update docs --- CHANGELOG.rst | 3 ++- README.rst | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b5b2936..330bec1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,8 +8,9 @@ To be released * Added ``sheet`` optional parameter to ``Tournaments.stream_results``, and fix returned typed dict. * Added ``studies.import_pgn`` to import PGN to study * Added ``tv.stream_current_game_of_channel`` to stream the current TV game of a channel +* Added ``client.account.get_timeline`` to get user timeline -Thanks to @nicvagn, @tors42, @fitztrev and @trevorbayless for their contributions to this release. +Thanks to @nicvagn, @tors42, @fitztrev, @trevorbayless, and @srachmiletter for their contributions to this release. v0.13.2 (2023-12-04) -------------------- diff --git a/README.rst b/README.rst index e3f8fbc..774aacf 100644 --- a/README.rst +++ b/README.rst @@ -65,6 +65,7 @@ Most of the API is available: client.account.get_kid_mode client.account.set_kid_mode client.account.upgrade_to_bot + client.account.get_timeline client.analysis.get_cloud_evaluation From 1b1e712963c951dd046ad185259ebbe44bd4876b Mon Sep 17 00:00:00 2001 From: Sam Rachmil-Etter Date: Sun, 15 Sep 2024 14:57:11 -0500 Subject: [PATCH 3/4] fix typing --- berserk/clients/account.py | 9 ++++----- berserk/types/account.py | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/berserk/clients/account.py b/berserk/clients/account.py index a5cd8b9..0accaf7 100644 --- a/berserk/clients/account.py +++ b/berserk/clients/account.py @@ -1,11 +1,10 @@ from __future__ import annotations -from typing import Any, cast, Dict +from typing import cast from .. import models -from ..types.account import AccountInformation, Preferences +from ..types.account import AccountInformation, Preferences, TimelineEvents from .base import BaseClient -from ..formats import LIJSON from ..session import Params @@ -63,7 +62,7 @@ def upgrade_to_bot(self): path = "/api/bot/account/upgrade" self._r.post(path) - def get_timeline(self, since: int = 1356998400070, nb: int = 15) -> Dict[str, Any]: + def get_timeline(self, since: int = 1356998400070, nb: int = 15) -> TimelineEvents: """Get your timeline events. :param int since: timestamp to show events since, default 1356998400070 @@ -73,4 +72,4 @@ def get_timeline(self, since: int = 1356998400070, nb: int = 15) -> Dict[str, An path = "/api/timeline" params: Params = {"since": since, "nb": nb} - return self._r.get(path, fmt=LIJSON, params=params) + return cast(TimelineEvents, self._r.get(path, params=params)) diff --git a/berserk/types/account.py b/berserk/types/account.py index d6da3ee..b89ea50 100644 --- a/berserk/types/account.py +++ b/berserk/types/account.py @@ -1,6 +1,7 @@ from __future__ import annotations from datetime import datetime +from typing import Any from typing_extensions import TypedDict @@ -94,3 +95,8 @@ class Preferences(TypedDict, total=False): zen: int moveEvent: int rookCastle: int + + +class TimelineEvents(TypedDict): + entries: list[dict[str, Any]] + users: dict[str, Any] From 9ab205625668dd85041f73947ecf3a7fa7d16fc0 Mon Sep 17 00:00:00 2001 From: Sam Rachmil-Etter Date: Sun, 15 Sep 2024 14:59:26 -0500 Subject: [PATCH 4/4] update docstring with auth requirements --- berserk/clients/account.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/berserk/clients/account.py b/berserk/clients/account.py index 0accaf7..3a82af8 100644 --- a/berserk/clients/account.py +++ b/berserk/clients/account.py @@ -65,6 +65,8 @@ def upgrade_to_bot(self): def get_timeline(self, since: int = 1356998400070, nb: int = 15) -> TimelineEvents: """Get your timeline events. + Requires OAuth2 authorization. + :param int since: timestamp to show events since, default 1356998400070 :param int nb: max number of events to fetch, default 15 :return: timeline events of the authenticated user