1

I'm using API "chess.com" and I try to learn better dict:

{'url': 'https://www.chess.com/live/game/8554438187', 'pgn': '[Event "Live Chess"]\n[Site "Chess.com"]\n[Date "2021.03.03"]\n[Round "-"]\n[White "AHMEDAHMED1984"]\n[Black "pgmendormi"]\n[Result "0-1"]

i need url so i did:

data = get_player_game_archives(username).json

url = data['archives'][-1]
games = requests.get(url).json()

game = games['games'][-1]
print(games['games'][-1]['url'])

but how can I get "[Result "0-1"]" I tried:

print(games['games'][-1]['url'][1])

but it gives me only one character, do I have to do a loop?

And how?

Thanks for your answers :)

1
  • The .json() in data = ... seems to suggest that you're getting json data. Maybe json.loads(...) will be useful in this case? Commented Mar 4, 2021 at 14:26

1 Answer 1

1

games['games'][-1]['pgn'].splitlines()[-1] should do the trick

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the tips :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.