Updated /import with file mod check.
This commit is contained in:
parent
0d38808e16
commit
a1d3be4fed
35
main.py
35
main.py
@ -19,7 +19,6 @@ import config
|
|||||||
app = Flask(__name__, static_url_path="", static_folder="static")
|
app = Flask(__name__, static_url_path="", static_folder="static")
|
||||||
auth = HTTPBasicAuth()
|
auth = HTTPBasicAuth()
|
||||||
|
|
||||||
|
|
||||||
@auth.verify_password
|
@auth.verify_password
|
||||||
def verify_password(username, password):
|
def verify_password(username, password):
|
||||||
if not config.TEENYOPDS_ADMIN_PASSWORD:
|
if not config.TEENYOPDS_ADMIN_PASSWORD:
|
||||||
@ -47,6 +46,10 @@ def healthz():
|
|||||||
def import2sql():
|
def import2sql():
|
||||||
conn = sqlite3.connect('app.db')
|
conn = sqlite3.connect('app.db')
|
||||||
list = []
|
list = []
|
||||||
|
comiccount = 0
|
||||||
|
importcount = 0
|
||||||
|
skippedcount = 0
|
||||||
|
errorcount = 0
|
||||||
|
|
||||||
start_time = timeit.default_timer()
|
start_time = timeit.default_timer()
|
||||||
for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)):
|
for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)):
|
||||||
@ -55,7 +58,9 @@ def import2sql():
|
|||||||
#try:
|
#try:
|
||||||
if f.endswith('.cbz'):
|
if f.endswith('.cbz'):
|
||||||
try:
|
try:
|
||||||
|
comiccount = comiccount + 1
|
||||||
s = zipfile.ZipFile(f)
|
s = zipfile.ZipFile(f)
|
||||||
|
filemodtime = os.path.getmtime(f)
|
||||||
#s = gzip.GzipFile(f)
|
#s = gzip.GzipFile(f)
|
||||||
Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
|
Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
|
||||||
#print(Bs_data.select('Series')[0].text, file=sys.stderr)
|
#print(Bs_data.select('Series')[0].text, file=sys.stderr)
|
||||||
@ -73,25 +78,43 @@ def import2sql():
|
|||||||
except:
|
except:
|
||||||
TITLE="" #sometimes title is blank.
|
TITLE="" #sometimes title is blank.
|
||||||
PATH=f
|
PATH=f
|
||||||
UPDATED=str(datetime.datetime.now())
|
UPDATED=filemodtime
|
||||||
#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);
|
||||||
|
query = "SELECT UPDATED FROM COMICS WHERE CVDB = '" + str(CVDB[0]) + "';"
|
||||||
|
savedmodtime = conn.execute(query).fetchone()[0]
|
||||||
|
#print(savedmodtime)
|
||||||
|
#print(float(savedmodtime))
|
||||||
|
#print(type(savedmodtime))
|
||||||
|
#print(type(filemodtime))
|
||||||
|
if savedmodtime < filemodtime:
|
||||||
|
#print(str(savedmodtime) + " is less than " + str(filemodtime))
|
||||||
|
|
||||||
|
print(str(CVDB[0]) + " - s: " + str(savedmodtime))
|
||||||
|
print(str(CVDB[0]) + " - f: " + str(filemodtime))
|
||||||
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.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()
|
||||||
|
print("Adding: " + str(CVDB[0]))
|
||||||
|
importcount = importcount + 1
|
||||||
|
else:
|
||||||
|
# print("Skipping: " + str(CVDB[0]))
|
||||||
|
skippedcount = skippedcount + 1
|
||||||
except:
|
except:
|
||||||
|
errorcount = errorcount + 1
|
||||||
print(f,file=sys.stdout)
|
print(f,file=sys.stdout)
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
elapsed = timeit.default_timer() - start_time
|
elapsed = timeit.default_timer() - start_time
|
||||||
print(elapsed)
|
elapsed_time = "IMPORTED IN: " + str(round(elapsed,2)) + "s"
|
||||||
|
print(elapsed_time)
|
||||||
return str(elapsed)
|
return elapsed_time + "<br>Comics: " + str(comiccount) + "<br>Imported: " + str(importcount) + "<br>Skipped: " + str(skippedcount) + "<br>Errors: " + str(errorcount)
|
||||||
|
|
||||||
@app.route("/content/<path:path>")
|
@app.route("/content/<path:path>")
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def send_content(path):
|
def send_content(path):
|
||||||
|
print('content')
|
||||||
return send_from_directory(config.CONTENT_BASE_DIR, path)
|
return send_from_directory(config.CONTENT_BASE_DIR, path)
|
||||||
|
|
||||||
@app.route("/catalog")
|
@app.route("/catalog")
|
||||||
@ -103,7 +126,7 @@ def catalog(path=""):
|
|||||||
#print(request.root_url)
|
#print(request.root_url)
|
||||||
c = fromdir(request.root_url, request.url, config.CONTENT_BASE_DIR, path)
|
c = fromdir(request.root_url, request.url, config.CONTENT_BASE_DIR, path)
|
||||||
elapsed = timeit.default_timer() - start_time
|
elapsed = timeit.default_timer() - start_time
|
||||||
#print("RENDERED IN: " + str(elapsed))
|
print("RENDERED IN: " + str(round(elapsed,2))+"s")
|
||||||
|
|
||||||
return c.render()
|
return c.render()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user