Compare commits

...

2 Commits

Author SHA1 Message Date
f54414c300 pushed tentative fix for import 2022-06-07 21:44:57 +02:00
d921c92aed added manual import test 2022-06-07 21:41:36 +02:00
4 changed files with 67 additions and 7 deletions

View File

@ -65,3 +65,9 @@ In the `config.py` file you need to change like 4 from `"/library"` to your comi
python3 main.py python3 main.py
# Notes
5865 files in 274 seconds

View File

@ -1,8 +1,8 @@
import os import os
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/library") #CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/library")
#CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/home/drudoo/ComicsTest/Comics") CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/home/drudoo/ComicsTest/Comics")
TEENYOPDS_ADMIN_PASSWORD = os.getenv("TEENYOPDS_ADMIN_PASSWORD", None) TEENYOPDS_ADMIN_PASSWORD = os.getenv("TEENYOPDS_ADMIN_PASSWORD", None)
users = {} users = {}

51
import.py Normal file
View File

@ -0,0 +1,51 @@
import zipfile
from bs4 import BeautifulSoup
import time
import config
import os,sys
import time
import sqlite3
import timeit
import re
import datetime
conn = sqlite3.connect('app.db')
list = []
start_time = timeit.default_timer()
for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)):
for file in files:
f = os.path.join(root, file)
#try:
if f.endswith(".cbz"):
print("CBZ: " + f)
s = zipfile.ZipFile(f)
#s = gzip.GzipFile(f)
Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
#print(Bs_data.select('Series')[0].text, file=sys.stderr)
#print(Bs_data.select('Title')[0].text, file=sys.stderr)
CVDB=re.findall('(?<=\[CVDB)(.*)(?=].)', Bs_data.select('Notes')[0].text)
#list.append('CVDB'+CVDB[0] + ': ' + Bs_data.select('Series')[0].text + "(" + Bs_data.select('Volume')[0].text + ") : " + Bs_data.select('Number')[0].text )
#print(list, file=sys.stdout)
ISSUE=Bs_data.select('Number')[0].text
SERIES=Bs_data.select('Series')[0].text
VOLUME=Bs_data.select('Volume')[0].text
PUBLISHER=Bs_data.select('Publisher')[0].text
try:
TITLE=Bs_data.select('Title')[0].text
except:
TITLE=""
PATH=f
UPDATED=str(datetime.datetime.now())
#print(UPDATED,file=sys.stdout)
#sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')"
#print(sql,file=sys.stdout)
conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB[0], ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED))
conn.commit()
else:
print("NOT CBZ: " + f)
conn.close()
elapsed = timeit.default_timer() - start_time
print(elapsed)

11
main.py
View File

@ -37,7 +37,7 @@ def healthz():
@app.route('/import') @app.route('/import')
def import2sql(): def import2sql():
conn = sqlite3.connect('/app/app.db') conn = sqlite3.connect('app.db')
list = [] list = []
start_time = timeit.default_timer() start_time = timeit.default_timer()
@ -45,7 +45,6 @@ def import2sql():
for file in files: for file in files:
f = os.path.join(root, file) f = os.path.join(root, file)
#try: #try:
print(f,file=sys.stdout)
try: try:
s = zipfile.ZipFile(f) s = zipfile.ZipFile(f)
#s = gzip.GzipFile(f) #s = gzip.GzipFile(f)
@ -60,13 +59,17 @@ def import2sql():
SERIES=Bs_data.select('Series')[0].text SERIES=Bs_data.select('Series')[0].text
VOLUME=Bs_data.select('Volume')[0].text VOLUME=Bs_data.select('Volume')[0].text
PUBLISHER=Bs_data.select('Publisher')[0].text PUBLISHER=Bs_data.select('Publisher')[0].text
try:
TITLE=Bs_data.select('Title')[0].text TITLE=Bs_data.select('Title')[0].text
except:
TITLE="" #sometimes title is blank.
PATH=f PATH=f
UPDATED=str(datetime.datetime.now()) UPDATED=str(datetime.datetime.now())
#print(UPDATED,file=sys.stdout) #print(UPDATED,file=sys.stdout)
sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')" #sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')"
#print(sql,file=sys.stdout) #print(sql,file=sys.stdout)
conn.execute(sql); #conn.execute(sql);
conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB[0], ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED))
conn.commit() conn.commit()
except: except:
print(f,file=sys.stdout) print(f,file=sys.stdout)