-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtutorial.py
More file actions
33 lines (26 loc) · 1.02 KB
/
tutorial.py
File metadata and controls
33 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from chessdotcom import get_leaderboards, get_player_stats, get_player_game_archives
import pprint
import requests
printer = pprint.PrettyPrinter()
def print_leaderboards():
data = get_leaderboards().json
categories = data.keys()
for category in categories:
print('Category:', category)
for idx, entry in enumerate(data[category]):
print(f'Rank: {idx + 1} | Username: {entry["username"]} | Rating: {entry["score"]}')
def get_player_rating(username):
data = get_player_stats(username).json
categories = ['chess_blitz', 'chess_rapid', 'chess_bullet']
for category in categories:
print('Category:', category)
print(f'Current: {data[category]["last"]["rating"]}')
print(f'Best: {data[category]["best"]["rating"]}')
print(f'Best: {data[category]["record"]}')
def get_most_recent_game(username):
data = get_player_game_archives(username).json
url = data['archives'][-1]
games = requests.get(url).json()
game = games['games'][-1]
printer.pprint(game)
get_most_recent_game('timruscica')