Skip to main content

Fetches all games from chess.com for a specified period at a defined time control between players above a defined rating.

Project description

chesscom game fetcher

This module will fetch all the games played at a specified time control for a specified period from all players rated above a defined rating and then compile them into a CSV file. This is quite a specialised use case. If you wish to instead download the games of an specific player you can, but you may be better served by my online tool for this use case, Let's Do The Procedure.

You may also be interested in the chess.com package by saradzhyanartur, which this module uses to access the chesscom API.

Getting Started

Installation

pip install chesscom-game-fetcher

Basic Usage

The module relies upon the Fetcher class, which uses its attributes to determine which games to fetch when its fetch() method is called.

from chesscom_game_fetcher import Fetcher
fetcher = Fetcher()
fetcher.fetch()
## Default settings will fetch all 3+0 games from the current
## month played between those rated 2800 and above.

Attributes can be set both during Fetcher initialisation on the instance itself. Check which settings your Fetcher instance will be using at any time by calling the check attribute.

from chesscom_game_fetcher import Fetcher
fetcher = Fetcher(min_rating=3000, min_opponent=3000)
fetcher.time_control = '180+1'

## This will print a table of the instance's fetch settings.
fetcher.check

## This will now fetch all 3+1 games from the current month
## played between those rated 3000 and above.
fetcher.fetch()

Specialised Usage

The individual methods Fetcher.fetch() calls can, if you wish, be used manually. This is how you fetch games from specific players.

Fetch Players

Fetcher.fetch_players() returns a list of all those rated above Fetcher.min_rating

Fetch Games

Fetcher.fetch_games(player_list, year, 'month')

  • player_list : a list of player names.
  • year : year to search for games in. YYYY format.
  • month : two digit string for the month to search for games in. 'MM' format.
fetcher = Fetcher(min_rating=3000, min_opponent=3000)
player_list = fetcher.fetch_players()
games_list = fetcher.fetch_games(player_list, 2024, '04')
## games_list will contain all games played between
## those rated 3000 minimum in april 2024

Create CSV

Fetcher.generate_csv(games_list) Outputs a CSV file using a games_list created by Fetcher.fetch_games.

Fetcher.csv_directory and Fetcher.csv_name are used to create the file.

Attribute Reference Table

Attribute Default Type Description
min_rating 2800 int Players will be pulled from the leaderboard for this time_class until a player with a rating below min_rating is found.
min_opponent 2800 int Any games with an opponent rated below min_opponent will be discarded.
time_control '180' str Games without this time control will be discarded. time_control is set by total seconds for each player (+ increment in seconds if used). For example 180 will select 3+0 games whilst 180+1 will select 3+1 games.
time_class 'blitz' str Must be one of: daily, rapid, blitz or bullet
start_date '{ current year (4 digit) }/{ current month (2 digit) }' str Games will be pulled starting from this month. Format: YYYY/MM.
end_date '{ current year (4 digit) }/{ current month (2 digit) }' str Games will stop being pulled after this month. Format: YYYY/MM.
csv_directory '{ current terminal directory }' str Directory for the CSV file. By default it will be placed in the directory your terminal is using.
csv_name auto-generated if not provided str Name for the CSV file. Default format is: '{ time_class }_min{ min_rating }_minopp{ min_opponent }_{ start_date }_{ end_date }.csv'

CSV File Output

By default this will go wherever your terminal was pointing when python was started with a file name automatically generated by the Fetcher instance itself. Change these with the csv_directory and csv_name attributes respectively.

The field names given to the CSV are: date_endtime, time_class, time_control, game_result, rating_diff, white_user, white_rating, white_result, black_user, black_rating, black_result

Author

Package developed by Scott Oxtoby. Emails to: pypi@oxtoby.uk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chesscom_game_fetcher-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chesscom_game_fetcher-1.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file chesscom_game_fetcher-1.0.1.tar.gz.

File metadata

  • Download URL: chesscom_game_fetcher-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for chesscom_game_fetcher-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b2b151c20be5f61ef9b77d1d71bdc0041d0855f0865090fd90db784df4e76cc0
MD5 2a71e8c690db7eb674b924bb60b06bd1
BLAKE2b-256 d0c6d3db3dc625da9e45de7098e1d09fa4b22d1138fe3b82f2759d75a4ece8f3

See more details on using hashes here.

File details

Details for the file chesscom_game_fetcher-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for chesscom_game_fetcher-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e8e17a6b619ca4d741265a69e7c62e2327d6d2d47cb871bdeb4e7c011f1e819
MD5 519c197e7d22318f74084c116a9ad19c
BLAKE2b-256 6f5499194df79f41a3b6c54b5bd1fc41658eef1e02e12a3bb799746b5e39a1ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page