Compare commits
2 Commits
e239eb7159
...
8c69a958de
Author | SHA1 | Date | |
---|---|---|---|
8c69a958de | |||
c9dc8307b7 |
93
main.py
93
main.py
@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, render_template, send_from_directory, request
|
from flask import Flask, redirect,url_for, render_template, send_from_directory, request
|
||||||
from flask_httpauth import HTTPBasicAuth
|
from flask_httpauth import HTTPBasicAuth
|
||||||
from werkzeug.security import check_password_hash
|
from werkzeug.security import check_password_hash
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
@ -13,6 +13,7 @@ import re
|
|||||||
import datetime
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import numpy as np
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
@ -35,12 +36,38 @@ def verify_password(username, password):
|
|||||||
):
|
):
|
||||||
return username
|
return username
|
||||||
|
|
||||||
|
@app.route("/", methods=['POST','GET'])
|
||||||
@app.route("/")
|
|
||||||
def startpage():
|
def startpage():
|
||||||
#result = "Hello, World!"
|
#result = "Hello, World!"
|
||||||
|
config._print(request.method)
|
||||||
|
if request.method == 'POST':
|
||||||
|
if request.form.get('Create') == 'Create':
|
||||||
|
# pass
|
||||||
|
config._print("open")
|
||||||
conn = sqlite3.connect('app.db')
|
conn = sqlite3.connect('app.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("create table COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED,PRIMARY KEY(CVDB))")
|
||||||
|
result = cursor.fetchall()
|
||||||
|
conn.close()
|
||||||
|
config._print("Encrypted")
|
||||||
|
elif request.form.get('Import') == 'Import':
|
||||||
|
# pass # do something else
|
||||||
|
config._print("Decrypted")
|
||||||
|
return redirect(url_for('import2sql'))
|
||||||
|
elif request.form.get('Generate') == 'Generate':
|
||||||
|
config._print("Generate Covers from Start page")
|
||||||
|
return redirect(url_for('generate'))
|
||||||
|
else:
|
||||||
|
# pass # unknown
|
||||||
|
return render_template("first.html")
|
||||||
|
elif request.method == 'GET':
|
||||||
|
# return render_template("index.html")
|
||||||
|
config._print("No Post Back Call")
|
||||||
|
conn = sqlite3.connect('app.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
cursor.execute("select * from comics LIMIT " + str(config.DEFAULT_SEARCH_NUMBER) + ";")
|
cursor.execute("select * from comics LIMIT " + str(config.DEFAULT_SEARCH_NUMBER) + ";")
|
||||||
result = cursor.fetchall()
|
result = cursor.fetchall()
|
||||||
|
|
||||||
@ -53,13 +80,38 @@ def startpage():
|
|||||||
cursor.execute("SELECT volume, COUNT(volume) FROM comics GROUP BY volume ORDER BY volume;")
|
cursor.execute("SELECT volume, COUNT(volume) FROM comics GROUP BY volume ORDER BY volume;")
|
||||||
volume = cursor.fetchall()
|
volume = cursor.fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
x = []
|
x = []
|
||||||
y = []
|
y = []
|
||||||
for i in volume:
|
for i in volume:
|
||||||
x.append(i[0])
|
x.append(i[0])
|
||||||
y.append(i[1])
|
y.append(i[1])
|
||||||
conn.close()
|
conn.close()
|
||||||
return render_template("start.html", result=result,pub_list=pub_list,count=count,x=x,y=y)
|
|
||||||
|
try:
|
||||||
|
total = np.sum(np.array(volume).astype('int')[:,1],axis=0)
|
||||||
|
dir_path = r'thumbnails'
|
||||||
|
covers = 0
|
||||||
|
for path in os.listdir(dir_path):
|
||||||
|
if os.path.isfile(os.path.join(dir_path,path)):
|
||||||
|
covers += 1
|
||||||
|
config._print("covers: " + str(covers))
|
||||||
|
except Exception as e:
|
||||||
|
config._print(e)
|
||||||
|
return render_template("start.html", first=False,result=result,pub_list=pub_list,count=count,x=x,y=y,total=total,covers=covers)
|
||||||
|
except:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
config._print('first')
|
||||||
|
return render_template("start.html",first=True)
|
||||||
|
|
||||||
|
#@app.route("/first", methods=['GET', 'POST'])
|
||||||
|
#def first():
|
||||||
|
# return render_template('first.html',result=result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/healthz")
|
@app.route("/healthz")
|
||||||
def healthz():
|
def healthz():
|
||||||
@ -85,7 +137,8 @@ def generate():
|
|||||||
Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
|
Bs_data = BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
|
||||||
CVDB=extras.get_cvdb(Bs_data.select('Notes'))
|
CVDB=extras.get_cvdb(Bs_data.select('Notes'))
|
||||||
if force == 'True':
|
if force == 'True':
|
||||||
cover = s.open(filelist[1]).read()
|
ext = [i for i, x in enumerate(filelist) if re.search("(?i)\.jpg|png|jpeg$", x)]
|
||||||
|
cover = s.open(filelist[ext[0]]).read()
|
||||||
|
|
||||||
image = Image.open(BytesIO(cover))
|
image = Image.open(BytesIO(cover))
|
||||||
image.thumbnail(config.MAXSIZE,Image.ANTIALIAS)
|
image.thumbnail(config.MAXSIZE,Image.ANTIALIAS)
|
||||||
@ -97,7 +150,13 @@ def generate():
|
|||||||
#c.close()
|
#c.close()
|
||||||
generated = generated + 1
|
generated = generated + 1
|
||||||
elif Path(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg").exists() == False:
|
elif Path(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg").exists() == False:
|
||||||
cover = s.open(filelist[1]).read()
|
ext = [i for i, x in enumerate(filelist) if re.search("(?i)\.jpg|png|jpeg$", x)]
|
||||||
|
config._print(filelist)
|
||||||
|
config._print(ext)
|
||||||
|
config._print(filelist[ext[0]])
|
||||||
|
cover = s.open(filelist[ext[0]]).read()
|
||||||
|
#xyz = [i for i, x in enumerate(filelist) if re.match('*\.py$',x)]
|
||||||
|
#config._print(xyz)
|
||||||
image = Image.open(BytesIO(cover))
|
image = Image.open(BytesIO(cover))
|
||||||
image.thumbnail(config.MAXSIZE,Image.ANTIALIAS)
|
image.thumbnail(config.MAXSIZE,Image.ANTIALIAS)
|
||||||
image.save(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg")
|
image.save(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg")
|
||||||
@ -186,7 +245,7 @@ def import2sql():
|
|||||||
@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')
|
#print('content')
|
||||||
return send_from_directory(config.CONTENT_BASE_DIR, path)
|
return send_from_directory(config.CONTENT_BASE_DIR, path)
|
||||||
|
|
||||||
@app.route("/image/<path:path>")
|
@app.route("/image/<path:path>")
|
||||||
@ -198,20 +257,20 @@ def image(path):
|
|||||||
@app.route("/catalog/<path:path>")
|
@app.route("/catalog/<path:path>")
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def catalog(path=""):
|
def catalog(path=""):
|
||||||
config._print("path: " + path)
|
#config._print("path: " + path)
|
||||||
config._print("root_url: " + request.root_url)
|
#config._print("root_url: " + request.root_url)
|
||||||
config._print("url: " + request.url)
|
#config._print("url: " + request.url)
|
||||||
config._print("CONTENT_BASE_DIR: " + config.CONTENT_BASE_DIR)
|
#config._print("CONTENT_BASE_DIR: " + config.CONTENT_BASE_DIR)
|
||||||
#print("PRESSED ON")
|
#print("PRESSED ON")
|
||||||
start_time = timeit.default_timer()
|
start_time = timeit.default_timer()
|
||||||
#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)
|
||||||
print("c: ")
|
#print("c: ")
|
||||||
pprint(vars(c))
|
#pprint(vars(c))
|
||||||
for x in c.entries:
|
#for x in c.entries:
|
||||||
for y in x.links:
|
# for y in x.links:
|
||||||
pprint(y.href)
|
# pprint(y.href)
|
||||||
print("------")
|
#print("------")
|
||||||
elapsed = timeit.default_timer() - start_time
|
elapsed = timeit.default_timer() - start_time
|
||||||
print("-----------------------------------------------------------------------------------------------------------------------")
|
print("-----------------------------------------------------------------------------------------------------------------------")
|
||||||
print("RENDERED IN: " + str(round(elapsed,2))+"s")
|
print("RENDERED IN: " + str(round(elapsed,2))+"s")
|
||||||
|
@ -55,12 +55,12 @@ class Entry(object):
|
|||||||
#print(kwargs)
|
#print(kwargs)
|
||||||
#print(kwargs["links"][0].get("rpath"))
|
#print(kwargs["links"][0].get("rpath"))
|
||||||
#print("--end entry.py")
|
#print("--end entry.py")
|
||||||
|
try:
|
||||||
if kwargs["links"][0].get("type") == 'application/x-cbz':
|
if kwargs["links"][0].get("type") == 'application/x-cbz':
|
||||||
f=self.links[0].get("rpath")+"/"+self.title+".cbz"
|
f=self.links[0].get("rpath")+"/"+self.title+".cbz"
|
||||||
if os.path.exists(f):
|
if os.path.exists(f):
|
||||||
s = zipfile.ZipFile(f)
|
s = zipfile.ZipFile(f)
|
||||||
self.size = extras.get_size(f, 'mb')
|
#self.size = extras.get_size(f, 'mb')
|
||||||
data=BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
|
data=BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
|
||||||
#self.cover=s.open('P00001.jpg').read()
|
#self.cover=s.open('P00001.jpg').read()
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class Entry(object):
|
|||||||
else:
|
else:
|
||||||
config._print("No Writer found: " + str(data.select('Writer')))
|
config._print("No Writer found: " + str(data.select('Writer')))
|
||||||
|
|
||||||
self.cover = "/image/" + extras.get_cvdb(data.select('Notes')) + ".jpg"
|
#self.cover = "/image/" + extras.get_cvdb(data.select('Notes')) + ".jpg"
|
||||||
|
|
||||||
if data.select('Summary') != []:
|
if data.select('Summary') != []:
|
||||||
self.summary = data.select('Summary')[0].text
|
self.summary = data.select('Summary')[0].text
|
||||||
@ -94,6 +94,8 @@ class Entry(object):
|
|||||||
else:
|
else:
|
||||||
self.title = kwargs["title"]
|
self.title = kwargs["title"]
|
||||||
#self.title = data.select('Title')[0].text
|
#self.title = data.select('Title')[0].text
|
||||||
|
except Exception as e:
|
||||||
|
config._print(e)
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
return self._data.get(key, None)
|
return self._data.get(key, None)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<entry>
|
<entry>
|
||||||
<title>{{ entry.title }}</title>
|
<title>{{ entry.title }}</title>
|
||||||
<id>{{ entry.id }}</id>
|
<id>{{ entry.id }}</id>
|
||||||
<summary type="text">{{ entry.summary }}</summary>
|
m!-- <summary type="text">{{ entry.summary }}</summary> -->
|
||||||
{% for author in entry.authors %}
|
{% for author in entry.authors %}
|
||||||
<author>
|
<author>
|
||||||
<name>{{ author }}</name>
|
<name>{{ author }}</name>
|
||||||
|
14
templates/first.html
Normal file
14
templates/first.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form method="post" action="/">
|
||||||
|
|
||||||
|
<input type="submit" value="Encrypt" name="Encrypt"/>
|
||||||
|
<input type="submit" value="Decrypt" name="Decrypt" />
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
<p>{{ result }}</p>
|
@ -2,6 +2,27 @@
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
{% if first and request.args.get('first') == None %}
|
||||||
|
<form method="post">
|
||||||
|
<p>DB is missing table. <input type="submit" value="Create" name="Create"/>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if result == [] %}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<p>No comics imported. <input type="submit" value="Import" name="Import"/>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if total != covers %}
|
||||||
|
<form method="post">
|
||||||
|
<p>Some covers missing <input type="submit" value="Generate" name="Generate"/>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h1>Total Comics: {{ total }}</h1>
|
||||||
|
|
||||||
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
|
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
Loading…
Reference in New Issue
Block a user