DEV Community

Cover image for Python Scripts - chess.com API Tutorial
Envoy-VC
Envoy-VC

Posted on

Python Scripts - chess.com API Tutorial

Video Tutorial-

For this we need a module called chess.com
to install this simply open Terminal and run this command

pip install chess.com
Enter fullscreen mode Exit fullscreen mode

Source Code -

GitHub logo Envoy-VC / Python-Scripts

A Curated list of Awesome Python Scripts.

Python-Scripts

A Curated list of Awesome Python Scripts.

from chessdotcom import get_leaderboards , get_player_stats , get_player_game_archives
import pprint
import requests

printer = pprint.PrettyPrinter()

def get_leaderboard():
    data = get_leaderboards().json
    categories = data['leaderboards']
    daiy_leaderboards = categories['daily']
    for i in daiy_leaderboards:
        print(f" {i['rank']} | Username = {i['username']} | Score = {i['score']}")

def get_player_ratings(username):
    data = get_player_stats(username).json
    print(f"Ratings = {data['stats']['chess_blitz']['last']['rating']}")

def get_most_recent_game(username):
    data = get_player_game_archives(username).json
    url = data['archives'][-1]
    games = requests.get(url).json()
    last_game_played = games['games'][-1]
    printer.pprint(last_game_played)


get_leaderboard()
get_player_ratings('cschess')
get_most_recent_game('cschess')
Enter fullscreen mode Exit fullscreen mode

Subscribe to my YouTube Channel - https://www.youtube.com/channel/UCsYVtF7KLPiAanWgwGPYvpA

↤↤↤↤↤↤↤↤↤↤ 🆂🆄🅿🅿🅾🆁🆃 🅼🅴 ↦↦↦↦↦↦↦↦↦↦

► Bitcoin - bc1q832u7flm5uylpqq68ehrxwfqyfq9tgmln8pg9d

or just

Say Thanks

Discussion (0)