Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- # get all WGMs
- title = 'WGM'
- url = f'https://api.chess.com/pub/titled/{title}'
- r = requests.get(url)
- players = r.json()['players']
- # get stats for each player
- player_stats = []
- for player in players:
- url = f'https://api.chess.com/pub/player/{player}/stats'
- r = requests.get(url)
- stats = r.json()
- player_stats.append(stats)
- def calculate_average_rating(player_stats, time_control):
- ratings = []
- for stats in player_stats:
- if time_control in stats:
- current_rating = stats[time_control]['last']['rating']
- ratings.append(current_rating)
- average_rating = sum(ratings)//len(ratings)
- return average_rating
- # get blitz ratings
- average_blitz_rating = calculate_average_rating(player_stats, 'chess_blitz')
- # get bullet ratings
- average_bullet_rating = calculate_average_rating(player_stats, 'chess_bullet')
- # get rapid ratings
- average_rapid_rating = calculate_average_rating(player_stats, 'chess_rapid')
- # get specific player's rating
- player = 'nemsko'
- url = f'https://api.chess.com/pub/player/{player}/stats'
- r = requests.get(url)
- player_blitz_rating = r.json()['chess_blitz']['last']['rating']
- player_bullet_rating = r.json()['chess_bullet']['last']['rating']
- player_rapid_rating = r.json()['chess_rapid']['last']['rating']
- print(f'average blitz rating for {title}s: {average_blitz_rating}')
- print(f'current blitz rating for {player}: {player_blitz_rating}')
- print('')
- print(f'average bullet rating for {title}s: {average_bullet_rating}')
- print(f'current bullet rating for {player}: {player_bullet_rating}')
- print('')
- print(f'average rapid rating for {title}s: {average_rapid_rating}')
- print(f'current rapid rating for {player}: {player_rapid_rating}')
Advertisement
Add Comment
Please, Sign In to add comment