Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/chess_openings.db
Binary file not shown.
8 changes: 1 addition & 7 deletions lib/src/db/openings_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import 'package:sqflite/sqflite.dart';
part 'openings_database.g.dart';

// The dataset is from https://github.com/lichess-org/chess-openings
// and was simply imported in sqlite with:
// sqlite> .mode tabs
// sqlite> .import a.tsv openings
// sqlite> .import b.tsv openings
// sqlite> .import c.tsv openings
// sqlite> .import d.tsv openings
// sqlite> .import e.tsv openings
// It can be updated by running the script at scripts/update_openings_db.py

const _kDatabaseVersion = 2;
const _kDatabaseName = 'chess_openings$_kDatabaseVersion.db';
Expand Down
35 changes: 35 additions & 0 deletions scripts/update_openings_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

import csv
import os
import sqlite3
import subprocess
import sys

if len(sys.argv) <= 1:
print("Usage: ./update_openings_db.py <path to lichess-org/chess-openings repo>")
sys.exit(1)

path_to_chess_openings = sys.argv[1]

if not os.path.isdir(path_to_chess_openings):
print(f"Error: {path_to_chess_openings} is not a valid directory.")
sys.exit(1)

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)

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()
cur.execute('DELETE FROM openings;')
conn.commit()

cur.executemany('INSERT INTO openings (eco, name, pgn, uci, epd) VALUES (?, ?, ?, ?, ?);', to_db)
conn.commit()

conn.close()