Started working on #15. Added status page for Generate
This commit is contained in:
parent
ace4e9bcba
commit
41382cf1cd
@ -1,6 +1,7 @@
|
||||
import os
|
||||
from werkzeug.security import generate_password_hash
|
||||
from sys import platform
|
||||
import sys
|
||||
|
||||
CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/library") #docker
|
||||
|
||||
@ -32,7 +33,7 @@ MAXSIZE = (500,500)
|
||||
|
||||
def _print(arg):
|
||||
if DEBUG:
|
||||
print(arg)
|
||||
print(arg,file=sys.stderr)
|
||||
|
||||
TEENYOPDS_ADMIN_PASSWORD = os.getenv("TEENYOPDS_ADMIN_PASSWORD", None)
|
||||
users = {}
|
||||
|
39
main.py
39
main.py
@ -13,14 +13,18 @@ import re
|
||||
import datetime
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
from io import BytesIO
|
||||
from threading import Thread
|
||||
|
||||
# for debugging
|
||||
from pprint import pprint
|
||||
####
|
||||
|
||||
generated = None
|
||||
|
||||
from opds import fromdir
|
||||
import config,extras
|
||||
|
||||
@ -57,7 +61,8 @@ def startpage():
|
||||
return redirect(url_for('import2sql'))
|
||||
elif request.form.get('Generate') == 'Generate':
|
||||
config._print("Generate Covers from Start page")
|
||||
return redirect(url_for('generate'))
|
||||
|
||||
return redirect(url_for('generate2'))
|
||||
else:
|
||||
# pass # unknown
|
||||
return render_template("first.html")
|
||||
@ -136,19 +141,30 @@ def search():
|
||||
config._print(e)
|
||||
return str(result)
|
||||
|
||||
@app.route("/generate")
|
||||
total = None
|
||||
#@app.route("/generate")
|
||||
def generate():
|
||||
force = request.args.get('force')
|
||||
config._print('GENERATES NOW!!!')
|
||||
force = 'True' #request.args.get('force')
|
||||
global generated
|
||||
global total
|
||||
total = 0
|
||||
generated = 0
|
||||
comiccount = 0
|
||||
files_without_comicinfo = 0
|
||||
errorcount = 0
|
||||
skippedcount = 0
|
||||
errormsg = ""
|
||||
for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)):
|
||||
for file in files:
|
||||
f = os.path.join(root,file)
|
||||
if f.endswith('.cbz'):
|
||||
total = total + 1
|
||||
for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)):
|
||||
for file in files:
|
||||
f = os.path.join(root, file)
|
||||
if f.endswith('.cbz'):
|
||||
config._print(generated)
|
||||
try:
|
||||
comiccount = comiccount + 1
|
||||
s = zipfile.ZipFile(f)
|
||||
@ -199,8 +215,25 @@ def generate():
|
||||
config._print(f)
|
||||
errormsg = str(e)
|
||||
return "Forced generation: " + str(force) + "<br>Comics: " + str(comiccount) + "<br>Generated: " + str(generated) + "<br>CBZ files without ComicInfo.xml: " + str(files_without_comicinfo) + "<br>Errors: " + str(errorcount) + "<br>Skipped: " + str(skippedcount) + "<br>" + errormsg
|
||||
config._print( "Forced generation: " + str(force) + "<br>Comics: " + str(comiccount) + "<br>Generated: " + str(generated) + "<br>CBZ files without ComicInfo.xml: " + str(files_without_comicinfo) + "<br>Errors: " + str(errorcount) + "<br>Skipped: " + str(skippedcount) + "<br>" + errormsg)
|
||||
|
||||
@app.route("/generate2")
|
||||
def generate2():
|
||||
t1 = Thread(target=generate)
|
||||
t1.start()
|
||||
return render_template('status.html')
|
||||
|
||||
|
||||
@app.route("/t2")
|
||||
def index():
|
||||
t1 = Thread(target=generate)
|
||||
t1.start()
|
||||
return render_template('status.html')
|
||||
|
||||
@app.route('/status',methods=['GET'])
|
||||
def getStatus():
|
||||
statusList = {'status':generated,'total':total}
|
||||
return json.dumps(statusList)
|
||||
|
||||
@app.route('/import')
|
||||
def import2sql():
|
||||
|
75
templates/status.html
Normal file
75
templates/status.html
Normal file
@ -0,0 +1,75 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
|
||||
<style>
|
||||
|
||||
body {
|
||||
background-color: #D64F2A;
|
||||
}
|
||||
|
||||
.progress {
|
||||
display: flex;
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.status {
|
||||
color: white;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.status h2 {
|
||||
padding: 50px;
|
||||
font-size: 80px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<title>Status Update</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="progress">
|
||||
<div class="status">
|
||||
<h2 id="innerStatus">Loading...</h2>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
var timeout;
|
||||
|
||||
async function getStatus() {
|
||||
|
||||
let get;
|
||||
|
||||
try {
|
||||
const res = await fetch("/status");
|
||||
get = await res.json();
|
||||
} catch (e) {
|
||||
console.error("Error: ", e);
|
||||
}
|
||||
|
||||
document.getElementById("innerStatus").innerHTML = Math.round(get.status / get.total * 100,0) + "%";
|
||||
|
||||
if (get.status == get.total){
|
||||
document.getElementById("innerStatus").innerHTML += " Done.";
|
||||
clearTimeout(timeout);
|
||||
// Simulate a mouse click:
|
||||
window.location.href = "/";
|
||||
return false;
|
||||
}
|
||||
|
||||
timeout = setTimeout(getStatus, 1000);
|
||||
}
|
||||
|
||||
getStatus();
|
||||
</script>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user