2023-10-16 21:58:50 +02:00
|
|
|
|
|
|
|
from flask import Flask,redirect,url_for,request,render_template
|
2023-10-17 18:25:38 +02:00
|
|
|
from datetime import datetime
|
|
|
|
## Import db class from func.py and initialise it
|
|
|
|
from func import db
|
|
|
|
db=db()
|
|
|
|
|
2023-10-16 21:58:50 +02:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
2023-10-17 18:25:38 +02:00
|
|
|
## 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]
|
|
|
|
|
2023-10-16 21:58:50 +02:00
|
|
|
|
|
|
|
## WEB FRONTEND
|
|
|
|
@app.route('/')
|
|
|
|
def homepage():
|
2023-10-17 18:25:38 +02:00
|
|
|
archives=db.get_n_archives()
|
|
|
|
return render_template("home.html", title="Homepage",archives=archives)
|
2023-10-16 21:58:50 +02:00
|
|
|
|
|
|
|
## API CALLS
|
|
|
|
|
|
|
|
# main driver function
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# run app if executed directly
|
|
|
|
app.run()
|