Skip to content

Instantly share code, notes, and snippets.

@Axeltherabbit
Last active March 29, 2021 04:32
Show Gist options
  • Save Axeltherabbit/fc93bdebf14858d71de26851d78e3c37 to your computer and use it in GitHub Desktop.
Save Axeltherabbit/fc93bdebf14858d71de26851d78e3c37 to your computer and use it in GitHub Desktop.
simple lichess puzzle database parser
from csv import reader
import sys
# puzzle database https://database.lichess.org/#puzzles
with open("lichess_db_puzzle.csv", "r") as f:
rating = int(sys.argv[1]) if len(sys.argv) > 1 else 1500
deviation = int(sys.argv[2]) if len(sys.argv) > 2 else 100
csv_reader = reader(f)
res = []
for row in csv_reader:
# PuzzleId,FEN,Moves,Rating,RatingDeviation,Popularity,NbPlays,Themes,GameUrl
p_id, p_rating, p_deviation, p_nbp = (
row[0],
int(row[3]),
int(row[4]),
int(row[6]),
)
if abs(p_rating - rating) + p_deviation <= deviation:
res.append(
(
p_id,
p_rating,
p_deviation,
p_nbp,
)
)
res.sort(key=lambda x: x[3])
for line in res:
print(f"id : {line[0]}, rating : {line[1]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment