rhgrant10 / berserk

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

Cannot create future dated tournament #22

Closed tranq2 closed 3 years ago

tranq2 commented 3 years ago

Description

I am trying to create a future dated tournament. I am having trouble passing a date. I have created a future date using date_time, converted it to timestamp, then cast to integer and string. The call fails saying the date is not in the future.

Love the work being done here with Berserk BTW and I am also new to Python so apologies if i have missed something obvious ...

What I Did

this was run on 31/1/21

relevant code fragments as follows


tourney_date = datetime(2021, 2, 1, 8, 00, 00)
datetime.fromtimestamp(int(tourney_date.timestamp())))
td_int = int(tourney_date.timestamp())
td_int_as_str = str(td_int)
tournament = client.tournaments.create(clock_time=2, clock_increment=3, minutes=30,
                                       berserkable = "true",
                                       start_date = td_int_as_str ,
                                       password="mdntest",
                                       conditions=myconditions)

Traceback (most recent call last):
  File "d:\users\nigel\appdata\local\programs\python\python38-32\lib\site-packages\berserk\exceptions.py", line 63, in _catch_exception
    response.raise_for_status()
  File "d:\users\nigel\appdata\local\programs\python\python38-32\lib\site-packages\requests\models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://lichess.org/api/tournament

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Users\Nigel\AppData\Local\Programs\Python\Python38-32\Requests.py", line 117, in <module>
    tournament = client.tournaments.create(clock_time=2, clock_increment=3, minutes=30,
  File "d:\users\nigel\appdata\local\programs\python\python38-32\lib\site-packages\berserk\clients.py", line 933, in create
    return self._r.post(path, json=payload,
  File "d:\users\nigel\appdata\local\programs\python\python38-32\lib\site-packages\berserk\session.py", line 64, in post
    return self.request('POST', *args, **kwargs)
  File "d:\users\nigel\appdata\local\programs\python\python38-32\lib\site-packages\berserk\session.py", line 54, in request
    raise exceptions.ResponseError(response)
berserk.exceptions.ResponseError: HTTP 400: Bad Request: {'startDate': ['**The date must be set in the future'**], 'error': {'startDate': ['The date must be set in the future']}}
tranq2 commented 3 years ago

Finally managed to sort this as follows using some utils in the berserk package tourney_date = datetime(2021, 3, 9, 18, 00, 000) tourney_date_millis = berserk.utils.to_millis(tourney_date) tourney_date_int = int(tourney_date_millis) tourney_date_string = str(tourney_date_int)

and pass tourney_date_string in to tournament create call