Skip to main content

Fetches all games from chess.com with rating specifiers

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.0.tar.gz (5.7 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.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chesscom_game_fetcher-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 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.0.tar.gz
Algorithm Hash digest
SHA256 97f041ea7310e1e34aa0fc35cb6ad8d2868a57855a1dc6222ac7e71a1966b534
MD5 9bdf33d4284d1484c2f2eff1eb27c7e7
BLAKE2b-256 c7fe3fcd0990259ab07989383dff020446d3b3bf6cd454172be33a47230aa089

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for chesscom_game_fetcher-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4541047818b82f3be871064a83b95e8dd20fedde94f2ef1c8148476930dd3f61
MD5 ee05335be4a437181bf51916b3e2e53c
BLAKE2b-256 1fdb3b073662f438bd43715b9d6a79651c2eb8f91ce81c3d3da4c6f57f6ba8a2

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