Repository navigation
Replies: 3 comments
|
@TBergh98 -- Thank you so much for sharing this! I think it's a great idea and I would like to incorporate it in scidCommunity so all users can use it. I think quite a few people will find it helpful (I already know there are other users who export games to a Lichess Study). I really appreciate how well you've documented this proposal and thought it through. Having a working plugin makes this a much easier task to incorporate in scidCommunity.. I will attribute this as to you and add you to "Contributors" once I've incorporated it. Your entry for this in the Game List Window is exactly where I think it belongs. When I incorporate it, I will add language translations for the other languages available in scidCommunity. Kindest regards. |
|
@TBergh98 -- Your feature (which I've tested and works really well!) is now incorporated in scidCommunity v5.1.4.62. If there are any modifications you want me to make, please let me know. A really nice contribution to the community! |
|
Thank you for the kind words, and for taking the time to test it! I’m really happy to contribute. I’ll keep using the feature myself, and if there’s anything I’d like to change I’ll ping you. Thanks again for all the work you put into this project! |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Hi! I wrote a small plugin,
30_lichess_study.tcl, that publishes games from a scidCommunity database straight into one of your Lichess studies, one chapter per game. It replaces the manual loop export PGN → open Lichess → find the study → add chapter → paste PGN with a single dialog.I made it for my own use, because it fits my workflow. I don't know whether it is something you'd want in the project. I'm sharing it here so that anyone with the same need can use the code.
As far as I can tell, nothing like this exists in the codebase yet. The lichess.org button in the PGN window uploads one game through
/api/importas an anonymous public game (not into a study). The Lichess tournament tool only reads broadcast studies.The plugin is a single Tcl file using the existing
plugins/mechanism. It changes no scidCommunity code. Branch: https://github.com/TBergh98/scidCommunity/tree/lichess-study-pluginScreenshots
Game List right-click menu: select games, right-click, Publish to Lichess study (N)...

Publish dialog: the list shows your own studies, most recently updated first (student names blacked out)

What it does
How it works
Authentication: a personal Lichess API token with the scopes
study:readandstudy:write. The dialog has a link that opens the Lichess token page with those scopes pre-selected. The token is stored in plain text in<user folder>/lichess_study/token.txt.HTTP: done with
curl, which ships with scidCommunity on Windows and is preinstalled on macOS and most Linux systems. The token is passed on stdin (-K -), so it never appears in the process list. Request bodies go through temporary files, so UTF-8 names and comments survive on Windows.Lichess endpoints used:
GET /api/accountGET /api/study/by/{user}GET /api/study/{id}.pgnPOST /api/studyPOST /api/study/{id}/import-pgnDELETE /api/study/{id}/{chapter}PGN export: the games are read with
sc_game pgn -base -gameNumber, so the board, the current game and the current base are not touched. Annotations are exported in a form Lichess understands:$n(Lichess shows them as !, ?!, +−, ...)[%csl]/[%cal]marks, so coloured squares and arrows appear in the studyBlank lines inside the movetext are removed, because Lichess splits a multi-game PGN at a blank line followed by
[.Edge cases handled
"error": "Too many chapters". So the plugin counts the free chapters first. If the games don't all fit, it asks what to do:POST /api/studycreates a study with one empty chapter, which counts toward the limit. The plugin deletes it after the import. With exactly 64 games, it imports the first game, deletes the empty chapter, then imports the other 63, so all 64 fit.rundll32, becausecmd /c startcuts URLs at the first&curl.exeis found next to the scidCommunity executable if it is not onPATHTests
tests/tcl/lichess_study_tk.tclruns the real dialogs underwish(xvfb-runin CI, added totcl-tests.yml). It talks to an in-memory fake Lichess and never contacts lichess.org. The fake reproduces:Scenarios covered:
curlis invokedThe automated tests use a fake so that CI needs no Lichess account or token, creates no real studies and does not depend on the network. On top of that, I use the plugin with my own Lichess account against the real API.
Known limits
curl.Would you be interested in this? Do you have any suggestions to make it better or safer? I'm open to any feedback. Thanks!
All reactions