zackclements / berserk Goto Github PK
View Code? Open in Web Editor NEWPython client for the lichess API
License: Other
Python client for the lichess API
License: Other
berserk-downstream 0.11.6
3.9.5
Lichess API has sort
param: https://lichess.org/api#operation/apiUserCurrentGame
But berserk is throwing TypeError: export_by_player() got an unexpected keyword argument 'sort'
Tried to call:
games = client.games.export_by_player(
user_a,
vs=user_b,
since=start,
rated='true',
sort='dateAsc',
)
The implementation of the broadcast API seems outdated as it doesn't support rounds.
More specifically, the following endpoints are not implemented:
/broadcast/{broadcastTournamentId}/new
/broadcast/{broadcastTournamentSlug}/{broadcastRoundSlug}/{broadcastRoundId}
/broadcast/round/{broadcastRoundId}/edit
And these are outdated:
syncUrl
, credit
, startsAt
, and throttle
parameters don't exist anymore./broadcast/round/{broadcastRoundId}/push
pip3 install berserk-downstream
resulted in dev dependencies being installed as well:
Successfully installed Jinja2-3.0.1 MarkupSafe-2.0.1 PyYAML-5.4.1 Pygments-2.10.0 Sphinx-2.3.1 alabaster-0.7.12 argh-0.26.2 attrs-21.2.0 babel-2.9.1 backports.entry-points-selectable-1.1.0 berserk-downstream-0.11.4 bleach-4.0.0 bumpversion-0.5.3 certifi-2021.5.30 charset-normalizer-2.0.4 codecov-2.0.22 coverage-5.0.1 deprecated-1.2.12 distlib-0.3.2 docutils-0.17.1 entrypoints-0.3 filelock-3.0.12 flake8-3.7.9 idna-3.2 imagesize-1.2.0 importlib-metadata-4.6.4 keyring-23.1.0 mccabe-0.6.1 more-itertools-8.8.0 ndjson-0.3.1 packaging-21.0 pathtools-0.1.2 pip-19.3.1 pkginfo-1.7.1 platformdirs-2.2.0 pluggy-0.13.1 py-1.10.0 pycodestyle-2.5.0 pyflakes-2.1.1 pyparsing-2.4.7 pytest-5.3.2 pytest-cov-2.8.1 pytest-runner-5.2 pytz-2021.1 readme-renderer-29.0 requests-2.26.0 requests-toolbelt-0.9.1 six-1.16.0 snowballstemmer-2.1.0 sphinx-rtd-theme-0.4.3 sphinxcontrib-applehelp-1.0.2 sphinxcontrib-devhelp-1.0.2 sphinxcontrib-htmlhelp-2.0.0 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-1.0.3 sphinxcontrib-serializinghtml-1.1.5 toml-0.10.2 tox-3.14.3 tqdm-4.62.1 twine-3.1.1 urllib3-1.26.6 virtualenv-20.7.2 watchdog-0.9.0 wcwidth-0.2.5 webencodings-0.5.1 wheel-0.33.6 wrapt-1.12.1 zipp-3.5.0
well, that.
Im using te last version of Berserk in a rpi zero w (a little machine but powerful enough for make the work.)
I import berserk at the beginning and all work pretty fine, except that always the FIRST MOVE to make in a game take almost 7 seconds more or less.
There could be a reason for this? i can maybe make something to avoid this?
Thanks!
ps.: i ask in the lichess discord and they tall me to look here in the code, but, I'm pretty nooby and, i look at the code but, dont understand what could be.
Thanks.
ps.2:This just happens to me or is expected?
Describe what you were trying to get done.
I am a AI engineer, I was making a self learning AI for lichess that I could play against, but it ended up with this error.
Tell us what happened, what went wrong, and what you expected to happen.
I was going to test the AI, I expected it to well, work! But fate has a different plan as I get this freak error.
nothing, I just coded it and followed the guide and command guide and everything.
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
Traceback (most recent call last):
File "/home/user/Desktop/ChessAI4/chessAI/agenttwo.py", line 794, in <module>
agent = DQNAgent()
^^^^^^^^^^
File "/home/user/Desktop/ChessAI4/chessAI/agenttwo.py", line 171, in __init__
self.client = berserk.Client(berserk.TokenSession(self.token))
^^^^^^^^^^^^^^
AttributeError: module 'berserk' has no attribute 'Client'
^CException ignored in: <module 'threading' from '/usr/lib/python3.11/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.11/threading.py", line 1583, in _shutdown
lock.acquire()
KeyboardInterrupt:
Is there a way to use the cloud-eval endpoint?
I'm trying to fetch information for one of the recent Chess960 Qualifier open arenas with client.tournaments.get_tournament
.
import berserk
client = berserk.Client()
print(client.tournaments.get_tournament("MuVtmdah"))
Traceback (most recent call last):
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/get_unique_players_in_tournament_list.py", line 4, in <module>
print(client.tournaments.get_tournament("MuVtmdah"))
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/clients.py", line 999, in get_tournament
return self._r.get(path, converter=models.Tournaments.convert_values)
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/session.py", line 60, in get
return self.request('GET', *args, **kwargs)
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/session.py", line 56, in request
return fmt.handle(response, is_stream=is_stream, converter=converter)
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/formats.py", line 35, in handle
return converter(self.parse(response))
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/models.py", line 27, in convert_values
data[k] = cls.convert(data[k])
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/models.py", line 16, in convert
return cls.convert_one(data)
File "/Users/qpwoeirut/OtherProgramming/LichessProjects/venv/lib/python3.9/site-packages/berserk/models.py", line 20, in convert_one
for k in set(data) & set(cls.conversions):
TypeError: 'int' object is not iterable
Running client.tournaments.get
works fine, if that helps. I made a quick workaround hack by changing the conversion code in models.py, but I'm not sure if that will break other things.
Original code (lines 11-16 in models.py)
class Model(metaclass=model):
@classmethod
def convert(cls, data):
if isinstance(data, (list, tuple)):
return [cls.convert_one(v) for v in data]
return cls.convert_one(data)
Modified code
class Model(metaclass=model):
@classmethod
def convert(cls, data):
if isinstance(data, (list, tuple)):
return [cls.convert_one(v) for v in data]
return data # only this last line changes
Let me know if you need any more information!
export_by_player does not actually take the clocks param, though the documentation says it does (and API allows it).
This appears to be a dupe of rhgrant10/berserk#14 (which seems unmaintained)
games = client.games.export_by_player(username="junglebook1", clocks=True)
TypeError: export_by_player() got an unexpected keyword argument 'clocks'
Games export API expects integer timestamps, but berserk sends floats.
If you go here: https://lichess.org/api#operation/apiGamesUser
You see that since
and until
expect integers.
utils.to_millis(dt)
does not return integer seconds, it returns floats, per https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp
As is, the berserk timestamps are completely ignored.
Try running the example from the docs, but I changed to a 10 minute window:
start = berserk.utils.to_millis(dt.datetime(2018, 12, 8, 1, 10))
end = berserk.utils.to_millis(dt.datetime(2018, 12, 8, 1, 20))
print(f'Query from {start} to {end}')
games = lichess.games.export_by_player('LeelaChess', since=start, until=end, max=300)
print(f'Found {len(list(games))} Leela games')
start, end = int(start), int(end) # Convert to ints
print(f'Query from {start} to {end}')
games = lichess.games.export_by_player('LeelaChess', since=start, until=end, max=300)
print(f'Found {len(list(games))} Leela games')
Output:
Query from 1544260200000.0 to 1544260800000.0
Found 300 Leela games # Hit max!
Query from 1544260200000 to 1544260800000
Found 3 Leela games # Presumably correct
I am trying to call the function get_realtime_statuses
.
import berserk
session = berserk.TokenSession(API_TOKEN)
client = berserk.Client(session=session)
client.users.get_realtime_statuses(['Sasageyo', 'Voinikonis_Nikita', 'Zugzwangerz'])
What i have got:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lichess/venv/lib/python3.8/site-packages/berserk/clients.py", line 193, in get_realtime_statuses
params = {'ids': ','.join(user_ids)}
TypeError: sequence item 0: expected str instance, list found
In source code of this function i've found this string:
params = {'ids': ','.join(user_ids)}
and withoung calling directly get_realtime_statuses
:
params = {'ids': ','.join(['Sasageyo', 'Voinikonis_Nikita', 'Zugzwangerz'])}
returns {'ids': 'Sasageyo,Voinikonis_Nikita,Zugzwangerz'}
The Broadcasts
method push_pgn_update
should have round_id
as a parameter instead of broadcast_id
, in accordance to Lichess API (https://lichess.org/api#operation/broadcastPush).
Currently the README still link to the old berserk docs.
in the current implementation only user list is given to lichess api althought another parameter withGameIds
is available: https://lichess.org/api#operation/apiUsersStatus
change seems easy to do and I can PR it but I'm wondering how you'd like to implement in reason of current star parameter? Maybe a new method should be a better way to be compatible with previous version?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.