update chess openings db (#2404)

* update chess openings db

* bump chess openings db version
This commit is contained in:
Trevor Fitzgerald
2025-12-02 04:18:56 -05:00
committed by GitHub
parent 85b33668a8
commit 09da70b636
3 changed files with 15 additions and 2 deletions
Binary file not shown.
+1 -1
View File
@@ -8,7 +8,7 @@ import 'package:sqflite/sqflite.dart';
// The dataset is from https://github.com/lichess-org/chess-openings
// It can be updated by running the script at scripts/update_openings_db.py
const _kDatabaseVersion = 3;
const _kDatabaseVersion = 4;
const _kDatabaseName = 'chess_openings$_kDatabaseVersion.db';
/// A provider for the openings database.
+14 -1
View File
@@ -21,15 +21,28 @@ subprocess.run(["make", "all"], cwd=path_to_chess_openings, check=True)
db_path = os.path.join(os.path.dirname(__file__), '../assets/chess_openings.db')
conn = sqlite3.connect(db_path)
old_openings = set()
new_openings = set()
openings_sql = 'SELECT eco || " " || name || " " || pgn FROM openings ORDER BY eco, name, pgn;'
with open(os.path.join(path_to_chess_openings, 'dist/all.tsv'), 'r') as f:
dr = csv.DictReader(f, delimiter='\t')
to_db = [(i['eco'], i['name'], i['pgn'], i['uci'], i['epd']) for i in dr]
cur = conn.cursor()
old_openings = set(row[0] for row in cur.execute(openings_sql))
cur.execute('DELETE FROM openings;')
conn.commit()
cur.executemany('INSERT INTO openings (eco, name, pgn, uci, epd) VALUES (?, ?, ?, ?, ?);', to_db)
conn.commit()
new_openings = set(row[0] for row in cur.execute(openings_sql))
conn.close()
print(f"Opening changes:")
print("```diff")
[print(f"- {o}") for o in sorted(old_openings - new_openings)]
[print(f"+ {o}") for o in sorted(new_openings - old_openings)]
print("```")