bookmobile/scripts/loader.py
2025-02-12 18:29:38 -08:00

15 lines
563 B
Python

import sqlite3
con = sqlite3.connect("index.db")
cur = con.cursor()
cur2 = con.cursor()
res = cur.execute("select books.id as id, books.path as path, data.name as name, data.format as format from books, data where books.id = data.book")
for id, path, name, format in res:
print(f"{path}/{name}.{format.lower()}")
filename = f"{path}/{name}.{format.lower()}"
with open(filename, mode='rb') as file:
fd = file.read()
cur2.execute("insert into book_content (id, content) values (?,?) on conflict(id) do nothing",(id, fd))
con.commit()