Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement api/timeline #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion berserk/clients/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
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 ..session import Params


class Account(BaseClient):
Expand Down Expand Up @@ -60,3 +61,17 @@ def upgrade_to_bot(self):
"""
path = "/api/bot/account/upgrade"
self._r.post(path)

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
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:param int since: timestamp to show events since, default 1356998400070
:param int nb: max number of events to fetch, default 15
:param since: only show events after this timestamp, default 1356998400070 (the earliest allowed by Lichess)
:param nb: max number of events to fetch, default 15

We generally leave out the types here since they are already given via the type hints.

:return: timeline events of the authenticated user
"""
path = "/api/timeline"
params: Params = {"since": since, "nb": nb}

return cast(TimelineEvents, self._r.get(path, params=params))
6 changes: 6 additions & 0 deletions berserk/types/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from datetime import datetime
from typing import Any

from typing_extensions import TypedDict

Expand Down Expand Up @@ -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]
Comment on lines +100 to +102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good day, the idea is not to have any Any in the response type.

Loading