3

Cross-posted stackoverflow, but nothing.


Both lichess and chess.com have the feature to play the variant chess960 live. However, only lichess has a graph showing how your live chess960 rating has changed over time. Lichess also shows other statistics like highest, lowest, best wins, worst losses, average opponent rating, etc. (chess.com does have this for correspondence chess960 though.)

I could create my own graph and statistics in Excel/Google Sheets by manually recording each game's date and my rating afterwards indicated beside my username, but...

Question: Is there a way to obtain, or what in general is the way to go about obtaining, ratings after each chess960 game using some kind of script that sees a player's public profile and then extracts the data?

I have a feeling this kind of script has been done before even if this was not specifically done for chess.com's live chess960. The script doesn't have to graph (pretty easy to do once you have to the data: just use excel/google sheets). I just need the script to collect all the dates and rating numbers for each line of the user's games.


Update 2: Fixed now. see the 'json' vs the 'preformed'. WOW.

Update 1: It appears Mike Steelson has an answer here, where the code is given as

=arrayformula( regexextract(split( substitute(substitute(substitute(getDataJSON(A1;"/games";"/pgn");"[";"");"]";"");"""";"") ;char(10));"\s.*") )

with an example given here

https://docs.google.com/spreadsheets/d/1MX1o5qdy0K3gTMzbimUV3SmFf-0XPCSJ8Vz4IjI-8Ak/copy

It appears there's a problem when it gets to the case of chess960 only. Consider for example this player: Replacing 'gmwso' with the player's username will yield a weird output. i imagine the output will be messier for mixed chess960 and chess.

3

Yes, it's possible to obtain the data you want. Chess.com has a REST API which is described in the following news post:

https://www.chess.com/news/view/published-data-api

You can use the following URL to get a list of monthly archives of a players games:

https://api.chess.com/pub/player/{username}/games/archives

In this list you will find URLs which look like this:

https://api.chess.com/pub/player/{username}/games/{YYYY}/{MM}

If you append /pgn to this URL, you will get get all the games in PGN format, which is probably simpler to parse.

Lets look at an example:

https://api.chess.com/pub/player/magnuscarlsen/games/2018/01/pgn

Here you will find games played by Magnus Carlsen in January 2018. This list contains a couple of Chess960 games, which are identified by the following tag:

[Variant "Chess960"]

The following tags will give you the UTC date and time of the game as well as the players ratings at the time:

[UTCDate "2018.01.03"]
[UTCTime "21:50:55"]
[WhiteElo "2706"]
[BlackElo "2940"]

Lichess has also an API to download games, which I already described here.

Code

Here's some simple Kotlin code to extract the data (you will need to change the file and user name):

import java.io.File

fun main() {
    val data = (File("ChessCom_magnuscarlsen_201801.pgn").readText().trim().split("\n\n\n").map {
        it.split('\n').filter { it.startsWith('[') }.map {
            val t = it.replace(Regex("[\\[\\]]"), "").split(' ', limit = 2)
            t[0] to t[1]
        }.toMap()
    })
    data.forEach {
        if (it["Variant"] == "\"Chess960\"") {
            println("${it["UTCDate"]} ${it["UTCTime"]} ${it[if (it["White"] == "\"MagnusCarlsen\"") "WhiteElo" else "BlackElo"]}")
        }
    }
}

Result:

"2018.01.03" "21:50:55" "2706"
"2018.01.03" "21:09:41" "2727"
"2018.01.03" "19:43:22" "2703"
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.