I'm trying to download and analyse my chess games that i played on lichess.org for a project, and as per their public api they state that the response should be returned in ndjson format, however using the .json() method on the response body yields an a JSONDecode error
I want to be able to extract game data for each game and so far that is how I have reached:
params = {
"perfType": "blitz,rapid,classical"
}
response = requests.get('https://lichess.org/api/games/user/RAMEZESSAM1', params=params)
And when iterating over the content:
for item in response.iter_lines():
print(item.decode())
Just the decoded response byte text for all of my games
Any help would be appreciated to extract the game one by one and maybe store them as a json object
Just like you set the
perfType
query parameter, you can also set thepgnInJson
parameter to true. This one defaults to false, that's why you get back just the pgn formatted response.https://lichess.org/api#operation/apiGamesUser
Give it a try !