Skip to main content

Making Anki notes of type Chess 2.0 for one color's positions in a PGN.

Project description

Ruff uv Built with Spacemacs

Instructions

Install the note type Chess 2.0 thus, and change its card's front and back templates to have var flip = false; thus. Run pip install pgnanki, and in Python run something like the following.

import io

import chess.pgn
import pgnanki

pgn = """[FEN "r1bq1bkr/ppp3pp/2n5/3np3/2B5/5Q2/PPPP1PPP/RNB1K2R w KQ - 2 8"]

8. Bxd5+ (8. Qxd5+ Qxd5 (8... Be6 9. Qxe6#) 9. Bxd5+ Be6 10. Bxe6#) 8... Qxd5
(8... Be6 9. Bxe6#) 9. Qxd5+ Be6 10. Qxe6# *"""

with io.StringIO(pgn) as stream:
    game = chess.pgn.read_game(stream)
with open("Fried-Liver-Attack.tsv", "x") as file:
    for line in pgnanki.yield_lines(game, opposite=False):
        print(line, file=file)

This example would write to a file named Fried-Liver-Attack.tsv the following.

#separator:tab
#html:false
#notetype:Chess 2.0
[FEN "r4bkr/ppp3pp/2n1b3/3Qp3/8/8/PPPP1PPP/RNB1K2R w KQ - 1 10"] 10. Qxe6# *
[FEN "r1b2bkr/ppp3pp/2n5/3qp3/8/5Q2/PPPP1PPP/RNB1K2R w KQ - 0 9"] 9. Qxd5+ Be6 10. Qxe6# *
[FEN "r2q1bkr/ppp3pp/2n1b3/3Bp3/8/5Q2/PPPP1PPP/RNB1K2R w KQ - 1 9"] 9. Bxe6# *
[FEN "r1bq1bkr/ppp3pp/2n5/3np3/2B5/5Q2/PPPP1PPP/RNB1K2R w KQ - 2 8"] 8. Bxd5+ ( 8. Qxd5+ Qxd5 ( 8... Be6 9. Qxe6# ) 9. Bxd5+ Be6 10. Bxe6# ) 8... Qxd5 ( 8... Be6 9. Bxe6# ) 9. Qxd5+ Be6 10. Qxe6# *

In Anki

  1. Click 'File' and 'Import...'.
  2. Choose the file like Fried-Liver-Attack.tsv.
  3. In the dialogue box 'Import File''s section 'Import options' choose the deck.
  4. Click Import.

Documentation

pgnanki's documentation is in its docstrings.

Copyright and License

Copyright (C) 2025 John Dawson

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

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

pgnanki-1.0.4.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgnanki-1.0.4-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file pgnanki-1.0.4.tar.gz.

File metadata

  • Download URL: pgnanki-1.0.4.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for pgnanki-1.0.4.tar.gz
Algorithm Hash digest
SHA256 9a2bb0f51fc5888e6b025264cc91c73a34861d78bdb4156b0cc40a035d4904d1
MD5 18c3b3de1fb8f6ba467cd7d65a59efae
BLAKE2b-256 32f961d0b82e43a77d300aeecdf869342b320db1e7bfe88bed652f850e682503

See more details on using hashes here.

File details

Details for the file pgnanki-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: pgnanki-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for pgnanki-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fb8b657bf5b7d47d6bb5a5c8d82318badd5151ea87d072daa1d01a8a9d586501
MD5 39c6575bfd5ec8a5e2d40302a8da45ca
BLAKE2b-256 4fc5992c80b51675a3d4567167139ae15d75ce3fce1e6ccb648586dad92c37df

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