Clean up remaining sqlite code
This commit is contained in:
parent
88575765b8
commit
5e641a23e4
2 changed files with 21 additions and 20 deletions
|
@ -3,5 +3,4 @@ set -e
|
|||
|
||||
. /venv/bin/activate
|
||||
|
||||
sqlite3 ${TUTOR_DATABASE} <./tables.sql
|
||||
exec tutor $@
|
||||
|
|
14
tutor/cli.py
14
tutor/cli.py
|
@ -5,7 +5,6 @@ import logging
|
|||
import os.path
|
||||
import re
|
||||
|
||||
import aiosqlite
|
||||
import click
|
||||
import httpx
|
||||
import humanize
|
||||
|
@ -116,15 +115,18 @@ def import_deck(ctx, filename, name):
|
|||
name = name or os.path.splitext(os.path.basename(filename))[0]
|
||||
|
||||
async def import_deck():
|
||||
async with aiosqlite.connect(ctx.obj["database"]) as db:
|
||||
deck_id = await tutor.database.store_deck(db, name)
|
||||
async with await psycopg.AsyncConnection.connect(
|
||||
ctx.obj["database"], autocommit=False
|
||||
) as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
deck_id = await tutor.database.store_deck(cursor, name)
|
||||
with tqdm.tqdm(lines) as bar:
|
||||
bar.write(f"Importing deck '{name}' [{deck_id}]")
|
||||
for line in bar:
|
||||
if match := line_pattern.match(line.strip()):
|
||||
groups = match.groupdict()
|
||||
cards = await tutor.database.advanced_search(
|
||||
db,
|
||||
cursor,
|
||||
tutor.search.Search(
|
||||
[tutor.search.Name(text=groups["name"])]
|
||||
),
|
||||
|
@ -132,9 +134,9 @@ def import_deck(ctx, filename, name):
|
|||
)
|
||||
if cards:
|
||||
await tutor.database.store_deck_card(
|
||||
db, deck_id, cards[0].oracle_id, int(groups["quantity"])
|
||||
cursor, deck_id, cards[0].oracle_id, int(groups["quantity"])
|
||||
)
|
||||
await db.commit()
|
||||
await conn.commit()
|
||||
|
||||
tornado.ioloop.IOLoop.current().run_sync(import_deck)
|
||||
|
||||
|
|
Loading…
Reference in a new issue