takos22 / codingame

Wrapper for the undocumented CodinGame API. Can be used both synchronously and asynchronlously.
https://codingame.readthedocs.io
MIT License
21 stars 7 forks source link

[BUG] Datetime format change #23

Closed TheNCProductions closed 1 year ago

TheNCProductions commented 1 year ago

Description

An error related to date format occur when trying to get the pending clash of code (with codingame.Client().get_pending_clash_of_code())

To Reproduce

Just call codingame.Client().get_pending_clash_of_code() and you will get this error:

  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/codingame/client/sync.py", line 128, in get_pending_clash_of_code
    return ClashOfCode(self._state, data[0])  # pragma: no cover
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/codingame/clash_of_code.py", line 130, in __init__
    self.creation_time = to_datetime(data["creationTime"])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/codingame/utils.py", line 102, in to_datetime
    return datetime.strptime(data, DT_FORMAT)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data 'Feb 10, 2023, 11:42:01 PM' does not match format '%b %d, %Y %I:%M:%S %p'

Environment information:

Suggestion

I just added a comma after the %Y in DT_FORMAT from the codingame/utils.py file, line 95, in order to match the data, like this: DT_FORMAT = "%b %d, %Y, %I:%M:%S %p". It solved the problem for me.

takos22 commented 1 year ago

Thanks for the report. Fixed in release 1.4.1, you can install it with pip install codingame==1.4.1.