Code Monkey home page Code Monkey logo

chess2lichess's Introduction

Chess.com to Lichess.org PGN Importer

Programmatically import games played on chess.com to lichess.org via PGN text.

I am really bad at chess and trying to be less bad at programming. I made this script as a little weekend project to practice the programming side of things.

Using this script, you can import all games from chess.com into your lichess.org profile in the current month that the script is being run in, from a specified month, or from a range of months. I have implemented a local "database" in .csv format in order to stop the script from trying to import games that are already on lichess.org and so that I can make some fun graphs showing how bad at chess I am in fun and interesting ways. I might just uncover hidden patterns in how bad I am at chess. In addition to the pseudo-database, the script now saves writes the full PGN text to a local text file. I made this to import my own chess.com games to lichess.org, but in theory you could import the games from any user you might like.

Let me know if there are bugs or features you would actually want added here.

P.S. If there are a lot of games, the script will take a while to run. I have limited it to one POST request every 7.5 seconds so as not to overload the lichess.org servers and raise a 429 error. I recommend running it with the -v/--verbose option in order to keep track of the progress.

To do

Improve management of the local PGN text so that games from each month are split into documents... maybe. I've yet to decide if this is actually a good idea.

Setup

  1. Obtain a lichess.org OAuth2 token - I granted my token full access, honestly not entirely sure what limited options are required for game import: https://lichess.org/account/oauth/token

  2. Set an environment variable called "LICHESS_TOKEN"

  3. git clone https://github.com/sean-workman/chess2lichess OR let's be honest, just download the script and put it wherever you want on your machine.

  4. Ensure that you have installed both the requests library and dateutil module in your working environment.

Usage

python chess2lichess.py username [-h] [-v] (-c | -m YYYY/MM | -r YYYY/MM YYYY/MM)

positional arguments:
  username              the chess.com username of the profile you want to download games from

options:
  -h, --help            show this help message and exit
  -v, --verbose         show information about number of games and progress
  -f [TYPE ...], --filter [TYPE ...]
                        filter which game types are imported - space separated
  -u, --utc             stop the script from converting date/time from UTC to local timezone
  -c, --current         import chess.com games from the current month to lichess.org
  -m YYYY/MM, --month YYYY/MM
                        import chess.com games from the specified month to lichess.org
  -r YYYY/MM YYYY/MM, --range YYYY/MM YYYY/MM
                        import chess.com games from months in the specified range to lichess.org

Examples

python chess2lichess.py hikaru -v -m 2022/08

The above command would fetch and import all 363 games that GM Hikaru played on chess.com in the month of August 2022 and let you know about the progress as it goes.

python chess2lichess.py hikaru -v -m 2022/08 -f blitz

The above command would fetch and import all 238 blitz games that GM Hikaru played on chess.com in the month of August 2022 and let you know about the progress as it goes.

python chess2lichess.py hikaru -v -m 2022/08 -f blitz bullet

The above command would fetch and import all 238 blitz games and 83 bullet games that GM Hikaru played on chess.com in the month of August 2022 and let you know about the progress as it goes.

chess2lichess's People

Contributors

sean-workman avatar

Stargazers

Ian Smith avatar Randy Henry avatar Ben Scholar avatar Ricky Grassmuck avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.