DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Update your GitHub profile with your chess.com games with a GitHub Action
Leonardo Montini for This is Learning

Posted on • Updated on

Update your GitHub profile with your chess.com games with a GitHub Action

When navigating through GitHub you may land on awesome profiles with "live" content being updated automatically, what kind of sorcery is this?

Let's start from the beginning!

Chess.com game history

Setup a personal profile

On top of the basic GitHub profile with pinned repos and the (very cool) contribution chart, you can fully customize the content in markdown basically by writing a README.md file, of your profile.

All you have to do is create a new repository with your username and put a README.md file in it.

In my case, my username is Balastrong so the repo will be Balastrong/Balastrong.

GitHub README.md badge

GitHub already notices that by adding this little badge in the home of your repo.

Bring it to life with GitHub Actions!

I'm sure you know the existence of GitHub Actions. Well, they can be used to edit files in your repository, right?

Now, the file you're going to edit is README.md and it will fetch some content from the internet, before formatting and putting it into your file.

Chess.com games!

Chess.com logo

Now that we have the combination profile + actions, we can make the magic!

All you need is to use this action: Chess.com Games & Stats [Marketplace], [Repository].

You can find the instruction there!
In short, you just need to two two basic steps:

1. Setup a placeholder in your README.md

You can control where the data will appear by putting this inside your file:

<!--START_SECTION:chessStats-->

<!--END_SECTION:chessStats-->
Enter fullscreen mode Exit fullscreen mode

2. Setup the action

GitHub helps you setting up a new action, but anyway it's just adding a new file in .github/workflows in your repository and that's it.

The content is as simple as:

name: Chess Stats Action

on:
  schedule:
    - cron: '0 0 * * *' # Runs at 00:00 UTC every day
  workflow_dispatch:

jobs:
  update-readme:
    name: Update readme with your chess stats and games
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: Balastrong/chess-stats-action@master
        with:
          CHESS_USERNAME: <Your chess.com Username>
Enter fullscreen mode Exit fullscreen mode

Just replace <Your chess.com Username> and you're good to go!

With the current cron schedule it will run by itself ad midnight UTC, but thanks to workflow_dispatch you can also run the action manually at any time.

You can see a live example at the bottom of my profile: https://github.com/Balastrong/

Getting the games

Here some additional context on the APIs, you might be curious about it!

Chess.com has some APIs but not exactly a complete game list. An official source of info is their Developer Community.

For some reason, you can only get the games already grouped by year/month, in the format:

https://api.chess.com/pub/player/{username}/games/{YYYY}/{MM}
Enter fullscreen mode Exit fullscreen mode

They call this "archive".

You can also get a list of available archives for a player:

https://api.chess.com/pub/player/{username}/games/archives
Enter fullscreen mode Exit fullscreen mode

Since my goal was to get the last N games and I cannot know how many games an archive has, I decided to request the archives first, and then call them one by one until I get the desired amount of games (or I requested 5 archives, that's enough).

Aaand... it kind of works :)


Thanks for reading my post, I hope you find it interesting!
Feel free to follow me to get notified when new articles are out ;)



You can also follow me on GitHub or Twitter, you can find the links here directly on my GitHub profile!

Hello, Leonardo here πŸ‘‹

I'm a full stack developer (mostly focused on frontend these days) and I like working on tools for developers.

You can find on GitHub my contributions to public Javascript/Typescript based projects, but I also like C# and Scala.

Let's stay in touch!

Linkedin Stack Overflow Youtube Twitter


πŸ“• Top projects I've contributed to

vscode vscode-js-debug wrand date-fns zod chess-stats-action


πŸ“Š Github stats

Expand to see my stats!

Balastrong's Github StatsBalastrong's Top Languages


⚑ Recent GitHub Activity

  1. ❗️ Closed issue #17 in Balastrong/wrand
  2. πŸŽ‰ Merged PR #18 in Balastrong/wrand
  3. πŸ’ͺ Opened PR #18 in Balastrong/wrand
  4. πŸ—£ Commented on #12 in Balastrong/chess-stats-action
  5. πŸŽ‰ Merged PR #13 in Balastrong/chess-stats-action

β™ŸοΈ Latest matches on Chess.com

Type Rapid ⏲️ Blitz ⚑ Bullet πŸ”«
Current 1215 895 1115
Best 1318 1345 1267
White βšͺ Black ⚫ Result πŸ† Date πŸ“… Position πŸ—ΊοΈ Type πŸ••
Balastrong Clashking123 checkmated ❌ 27/7/2022 Link Blitz
carlitodeliz Balastrong resigned ❌ 27/7/2022 Link Blitz
johanjessan Balastrong win πŸ₯‡ 27/7/2022 Link Blitz
bparis4542 Balastrong win
…

Top comments (1)

Collapse
balastrong profile image
Leonardo Montini Author

Thanks for reading this article!

Do you want to know more or dirty your hands and contribute to the project? There are a few open issues in the repo, if you want to give it a look here's the url: github.com/Balastrong/chess-stats-...

You can also leave there a star, much appreciated!
The programming language used is Typescript in case you were wondering :D

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.