rhgrant10 / berserk

Python client for the lichess API
https://berserk.readthedocs.io
Other
142 stars 36 forks source link

Berserk `since` and `until` should be integers #42

Open supermitch opened 2 years ago

supermitch commented 2 years ago

Description

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.

What I Did

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
supermitch commented 2 years ago

I see this is a duplicate of https://github.com/rhgrant10/berserk/issues/18