rar-index-py/flask/app.py

35 lines
783 B
Python
Raw Normal View History

from flask import Flask,redirect,url_for,request,render_template
from datetime import datetime
## Import db class from func.py and initialise it
from func import db
db=db()
app = Flask(__name__)
## CUSTOM FILTERS
@app.template_filter('ctime')
def timectime(s):
return datetime.utcfromtimestamp(s).strftime('%Y-%m-%d %H:%M')
@app.template_filter('spacer')
def timectime(s):
sizes=("B","KB","MB","GB","TB")
n=0
while s > 1000:
n+=1
s=s/1000
return str("%.2f" % s)+sizes[n]
## WEB FRONTEND
@app.route('/')
def homepage():
archives=db.get_n_archives()
return render_template("home.html", title="Homepage",archives=archives)
## API CALLS
# main driver function
if __name__ == '__main__':
# run app if executed directly
app.run()