Skip to content

Commit

Permalink
Apply PR feedback - do not manually add query param values to the pat…
Browse files Browse the repository at this point in the history
…h string.
  • Loading branch information
johndoknjas committed Oct 28, 2024
1 parent b62f817 commit 4551954
Showing 1 changed file with 27 additions and 45 deletions.
72 changes: 27 additions & 45 deletions berserk/clients/studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@
from .base import BaseClient


def append_query_params(
url: str,
clocks: bool,
comments: bool,
variations: bool,
source: bool,
orientation: bool,
) -> str:
pairs = {
"clocks": clocks,
"comments": comments,
"variations": variations,
"source": source,
"orientation": orientation,
}
return f"{url}?" + "&".join(f"{k}={str(pairs[k]).lower()}" for k in pairs)


class Studies(BaseClient):
"""Study chess the Lichess way."""

Expand All @@ -43,15 +25,15 @@ def export_chapter(
:return: chapter PGN
"""
path = append_query_params(
f"/api/study/{study_id}/{chapter_id}.pgn",
clocks,
comments,
variations,
source,
orientation,
)
return self._r.get(path, fmt=PGN)
path = f"/api/study/{study_id}/{chapter_id}.pgn"
params = {
"clocks": clocks,
"comments": comments,
"variations": variations,
"source": source,
"orientation": orientation,
}
return self._r.get(path, fmt=PGN, params=params)

def export(
self,
Expand All @@ -66,15 +48,15 @@ def export(
:return: iterator over all chapters as PGN
"""
path = append_query_params(
f"/api/study/{study_id}.pgn",
clocks,
comments,
variations,
source,
orientation,
)
yield from self._r.get(path, fmt=PGN, stream=True)
path = f"/api/study/{study_id}.pgn"
params = {
"clocks": clocks,
"comments": comments,
"variations": variations,
"source": source,
"orientation": orientation,
}
yield from self._r.get(path, fmt=PGN, stream=True, params=params)

def export_by_username(
self,
Expand All @@ -92,15 +74,15 @@ def export_by_username(
If not, only public (non-unlisted) studies are included.
return:iterator over all chapters as PGN"""
path = append_query_params(
f"/study/by/{username}/export.pgn",
clocks,
comments,
variations,
source,
orientation,
)
yield from self._r.get(path, fmt=PGN, stream=True)
path = f"/study/by/{username}/export.pgn"
params = {
"clocks": clocks,
"comments": comments,
"variations": variations,
"source": source,
"orientation": orientation,
}
yield from self._r.get(path, fmt=PGN, stream=True, params=params)

def import_pgn(
self,
Expand Down

0 comments on commit 4551954

Please sign in to comment.