rhgrant10 / berserk

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

Can't call get_activity_feed #40

Closed jube-pimy closed 2 years ago

jube-pimy commented 3 years ago

Description

I'm trying to get de recent activity of my account on lichess, but receive an error when looking for activity if user exists. If user doesn't exists on Lichess, then I receive an empty response ( which seems OK for me )

What I Did

def get_activity(): API_TOKEN = 'abcdef1234' session = berserk.TokenSession(API_TOKEN) client = berserk.Client(session=session) print(client.users.get_activity_feed('username'))

if name == 'main': get_activity()

C:\Users\user\Lichess\venv\Scripts\python.exe C:/Users/user/PycharmProjects/LichessGifDiscorder/main.py
Traceback (most recent call last):
  File "C:\Users\user\Lichess\main.py", line 32, in <module>
    get_activity()
  File "C:\Users\user\Lichess\main.py", line 28, in get_activity
    print(client.users.get_activity_feed('Pimy_1234'))
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\clients.py", line 235, in get_activity_feed
    return self._r.get(path, converter=models.Activity.convert)
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\session.py", line 60, in get
    return self.request('GET', *args, **kwargs)
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\session.py", line 56, in request
    return fmt.handle(response, is_stream=is_stream, converter=converter)
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\formats.py", line 35, in handle
    return converter(self.parse(response))
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\models.py", line 15, in convert
    return [cls.convert_one(v) for v in data]
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\models.py", line 15, in <listcomp>
    return [cls.convert_one(v) for v in data]
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\models.py", line 21, in convert_one
    data[k] = cls.conversions[k](data[k])
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\utils.py", line 63, in convert
    data[k] = func(data[k])
  File "C:\Users\user\Lichess\venv\lib\site-packages\berserk\utils.py", line 25, in datetime_from_seconds
    return datetime.fromtimestamp(ts, timezone.utc)
OSError: [Errno 22] Invalid argument

Process finished with exit code 1
Virinas-code commented 3 years ago

Hi @jube-pimy,

I tryed and found the bug.

https://github.com/rhgrant10/berserk/blob/1b000a47e47af140986f731c93aebaeca27dc163/berserk/models.py#L42

Replace datetime_from_seconds by datetime_from_millis.

Virinas-code commented 3 years ago

38 Fix it

jube-pimy commented 3 years ago

Nice news ! Thanks :) I'll try this as soon as possible

k0xff commented 2 years ago

Hi @jube-pimy,

I tryed and found the bug.

https://github.com/rhgrant10/berserk/blob/1b000a47e47af140986f731c93aebaeca27dc163/berserk/models.py#L42

Replace datetime_from_seconds by datetime_from_millis.

Much appreciated.

jube-pimy commented 2 years ago

Hello @Virinas-code !

(Even if late...) Thanks for the help, i'll try this with the fix !

Virinas-code commented 2 years ago

Hello @Virinas-code !

(Even if late...) Thanks for the help, i'll try this with the fix !

Thank you !

valvin1 commented 2 years ago

hello, just a quick message to confirm the issue and the fix but it would be great to have it in an official version :)

Virinas-code commented 2 years ago

Yes, but the PR is going to be merged.