diff --git a/main.py b/main.py index 6057612..aa694a3 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,14 @@ from flask_sqlalchemy import SQLAlchemy -from flask import Flask, jsonify +from flask import Flask, jsonify, render_template, request import json import os +import subprocess PATH = '/download' -app = Flask(__name__) +app = Flask(__name__, + template_folder="templates") app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://mdownload:mdownload@192.168.86.198:3306/Downloads' @@ -35,6 +37,9 @@ class url_metadata(db.Model): flag = db.Column(db.Text) base_url = db.Column(db.VARCHAR(length=10000)) +@app.route('/', methods=['GET']) +def index(): + return render_template("index.html") @app.route('/download', methods=['GET']) def download(): @@ -45,15 +50,22 @@ def download(): for each in result: book={} if 'http' in each.manga.name or 'https' in each.manga.url: - execute = """manga-py """ + each.manga.url + """ -n \"""" + each.manga.name + """\" -d \"""" + PATH + """\" -z -N""" + # execute = """manga-py """ + each.manga.url + """ -n \"""" + each.manga.name + """\" -d \"""" + PATH + """\" -z -N --print-json""" + exec_command = subprocess.Popen(['manga-py', each.manga.url, '-n', each.manga.name, '-d ' + PATH, '-z', '-N', '--print-json'], stdout=subprocess.PIPE) else: - execute = """manga-py """ + each.url_metadata.base_url+each.manga.url + """ -n \"""" + each.manga.name.strip('?') + """\" -d \"""" + PATH + """\" -z -N""" + print('nothing') + # execute = """manga-py """ + each.url_metadata.base_url+each.manga.url + """ -n \"""" + each.manga.name.strip('?') + """\" -d \"""" + PATH + """\" -z -N --print-json""" + exec_command = subprocess.Popen(['manga-py', each.url_metadata.base_url, each.manga.url, '-n', each.manga.name.strip('?'), '-d ' + PATH, '-z', '-N', '--print-json'], stdout=subprocess.PIPE) book['title'] = each.manga.name - book['command'] = execute - updated.append(book) - os.system(execute) + # book['command'] = 'nothing' - return jsonify(manga=updated) + # os.system(execute) + # exec_command = subprocess.Popen(execute, stdout=subprocess.PIPE) + book['output'] = exec_command.communicate() + updated.append(book) + + missing = check(passin=1) + return jsonify(manga=updated, missingFlags=missing[0], missingManga=missing[1]) @app.route('/upload', methods=['GET']) def upload_jason(): @@ -105,5 +117,32 @@ def active(): return jsonify(active=activbooks) +@app.route('/check/', methods=['GET']) +def check(passin=0): + passin=passin + missingManga = [] + missingFlags = [] + providerFlags = [] + mangaFlags = manga.query.with_entities(manga.url_flag).distinct() + providerFlagResult = url_metadata.query.all() + for each in providerFlagResult: + providerFlags.append(each.flag) + for each in mangaFlags: + if each.url_flag not in providerFlags: + missingFlags.append(each.url_flag) + for each in missingFlags: + mangaInfo = {} + badManga = manga.query.filter_by(url_flag=each).all() + for each in badManga: + mangaInfo['name'] = each.name + mangaInfo['url_flag'] = each.url_flag + mangaInfo['active'] = each.active + missingManga.append(mangaInfo) + + if passin == 1: + return missingFlags, missingManga + else: + return jsonify(missingFlags=missingFlags, missingManga=missingManga) + if __name__ == "__main__": app.run(host='0.0.0.0', debug=True) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..f2a18ac --- /dev/null +++ b/templates/index.html @@ -0,0 +1,10 @@ + + +
+ +