rhgrant10 / berserk

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

Timestamp inconsistency between the services #2

Closed sentrworks closed 5 years ago

sentrworks commented 5 years ago

Description

The timestamp types are not consistent between the services. While 'get_activity_feed(username)' returns timestamp in the format of python, 'export_by_player' returns Javascript timestamp.

Describe what you were trying to get done. 1- The ''export_by_player' API returns the timestamp value of milliseconds for 'createAt' parameter , e.g. '1541551788049' whereas the 'get_activity_feed(username)' API returns timestamp without milliseconds which compliance with python datetime parsers, e.g. '1541548800'

What I Did

I had to divide the timestamp values with '1000' if they have milliseconds as explained below.

JavaScript timestamp to Python datetime conversion: https://stackoverflow.com/questions/10286224/javascript-timestamp-to-python-datetime-conversion

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
rhgrant10 commented 5 years ago

Ultimately this is a consistency issue with the API. I'll see if there's any hope of fixing the API itself by asking the devs in the discord chat. If not then instead perhaps I can perform some sort of detection and convert them all into proper datetime objects.

rhgrant10 commented 5 years ago

Unfortunately it seems this is either somewhat by design or changing it would be troublesome without sacrificing backwards compatibility. I've got a somewhat elegant solution on the develop branch that I'll be releasing soon.

rhgrant10 commented 5 years ago

@sentrworks feel free to give it a whirl if you can and let me know if you find any issues before I release it :)

sentrworks commented 5 years ago

@rhgrant10 unfortunately it doesn't work. Despite I upgraded to berserk 0.1.2 to 0.2.1, in both versions the api "lichess.games.export_by_player(username=username,as_pgn=False,max=how_many_games,rated='true',moves='false')" returns 'createdAt' field in a timestamp format which needs to divide by 1000.

screenshot 2018-12-20 at 14 10 44
rhgrant10 commented 5 years ago

Yeah it's still on the develop branch. I haven't released it yet. I should be able to get to it this weekend though.

rhgrant10 commented 5 years ago

It's available now on the PyPI at v0.3.0 @sentrworks.