TorrentIndexer/indexer.py

54 lines
1.3 KiB
Python

#!/usr/bin/python3
# vim:ts=2 sw=2 sts=2 noexpandtab
import json, os
from flask import Flask, render_template, url_for, request
from werkzeug import secure_filename
uploadFolder = "upload"
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = uploadFolder
strings = None
settings = None
@app.route("/")
def index():
return render_template("search.html", strings=strings)
@app.route("/categories")
def categorys():
return render_template("categories.html", strings=strings)
@app.route("/create")
def create():
return render_template("create.html", categories=settings["categories"], strings=strings)
@app.route("/search", methods=['GET'])
def search():
return render_template("result.html", results=request.args.get("q", ""), strings=strings)
def getLocalString(language, descriptor):
if language in strings.keys():
if descriptor in strings[language].keys():
return strings[language][descriptor]
else:
return None
else:
return None
def init():
global strings
global settings
with open("strings.json", "r") as strings:
strings = json.load(strings)
with open("settings.json", "r") as settings:
settings = json.load(settings)
if __name__ == "__main__":
app.jinja_env.globals.update(getLocalString=getLocalString)
app.jinja_env.globals.update(json=json)
init()
print(settings["categories"].keys())
app.run(debug=True)