-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,40 @@ | ||
from contextlib import closing | ||
import csv | ||
import sqlite3 | ||
|
||
con = sqlite3.connect('data/openings_s6_1200.db') | ||
con.row_factory = sqlite3.Row | ||
|
||
cur = con.cursor() | ||
|
||
# dump positions | ||
cur.execute("SELECT * FROM positions;") | ||
with open("positions.csv", "w") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
# dump moves | ||
cur.execute(""" | ||
SELECT moves_map.*, positions.bwins, positions.wwins | ||
FROM moves_map, positions | ||
WHERE positions.id = moves_map.next_position_id | ||
ORDER BY position_id; | ||
""") | ||
with open("moves.csv", "w") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
# dump games | ||
cur.execute("SELECT * FROM games;") | ||
with open("games.csv", "w") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
# dump reference table for games and positions | ||
cur.execute("SELECT * FROM game_position_xref ORDER BY position_id;") | ||
with open("game_references.csv", "w") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
# done! | ||
con.close() | ||
|
||
total = "" | ||
|
||
with open("positions.csv") as t: | ||
total += t.read() + "\nTABLE\n" | ||
with open("games.csv") as t: | ||
with closing(sqlite3.connect('data/openings_s6_1200.db')) as con: | ||
con.row_factory = sqlite3.Row | ||
|
||
with closing(con.cursor()) as cur: | ||
# dump positions | ||
cur.execute("SELECT * FROM positions;") | ||
with open("positions.csv", "w", encoding="UTF-8") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
# dump games | ||
cur.execute("SELECT * FROM games;") | ||
with open("games.csv", "w", encoding="UTF-8") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
# dump reference table for games and positions | ||
cur.execute("SELECT * FROM game_position_xref ORDER BY position_id;") | ||
with open("game_references.csv", "w", encoding="UTF-8") as csv_file: | ||
csv_writer = csv.writer(csv_file, delimiter="\t") | ||
csv_writer.writerow([i[0] for i in cur.description]) | ||
csv_writer.writerows(cur) | ||
|
||
total: str = "" | ||
|
||
with open("positions.csv", encoding="UTF-8") as t: | ||
total += t.read() + "\nTABLE\n" | ||
with open("moves.csv") as t: | ||
with open("games.csv", encoding="UTF-8") as t: | ||
total += t.read() + "\nTABLE\n" | ||
with open("game_references.csv") as t: | ||
with open("game_references.csv", encoding="UTF-8") as t: | ||
total += t.read() | ||
|
||
with open("db_dump", "w") as t: | ||
with open("db_dump", "w", encoding="UTF-8") as t: | ||
t.write(total) |