contentmatcher/app/app.py

77 lines
2.3 KiB
Python

#!/usr/bin/python3
""""
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
"""
"""
from flask import Flask, render_template, Blueprint
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.sqltypes import TIMESTAMP
from flask_sqlalchemy import SQLAlchemy
from config import CONFIG
import datetime
from create_db import #baze?
# Flask app
app.config['SQLALCHEMY_DATABASE_URI'] = CONFIG['DB_CONNECTION']
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db=SQLAlchemy(app)
# DB session init
engine = create_engine(CONFIG['DB_CONNECTION'])
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
#Query DB for scan_song table
#query_scan_song = session.query(Scan_Song).all()
query = session.query(Scan_Song.id_scan, Scan_Song.id_song, Scan_Song.match_val, Song.naslov, Song.album, Song.izvajalec, Song.trajanje, Scan.timestamp).join(Song, Song.id == Scan_Song.id_song, isouter=True).join(Scan, Scan_Song.id_scan == Scan.id).limit(1000)
site= Blueprint('site', __name__,template_folder='templates')
@app.route("/")
def index():
try:
#predvajano_text = '<ul>'
skeni = list()
for scan in query:
scan_dict = dict()
scan_dict["id_scan"] = str(scan.id_scan)
scan_dict["id_song"] = str(scan.id_song)
scan_dict["match_val"] = str(scan.match_val)
scan_dict["naslov"] = scan.naslov
scan_dict["album"] = scan.album
scan_dict["izvajalec"] = scan.izvajalec
scan_dict["trajanje"] = str(scan.trajanje)
scan_dict["timestamp"] = str(scan.timestamp)
#predvajano_text += '<ol>' + id_scan + ' , ' + id_song + ' , ' + match_val +' , ' + naslov + ' , ' + album + ' , ' + izvajalec + ' , ' + trajanje + ' , ' + timestamp + '</ol>'
#predvajano_text += '</ul>'
skeni.append(scan_dict)
return render_template(
"index.html",
skeni=skeni,
date = datetime.date.today().strftime("%d.%m.%y")
)
except Exception as e:
error_text = "<p>ni zadetkov:<br>" + str(e) + "</p>"
hed = '<h1>Komada ni v bazi.</h1>'
return hed + error_text
if __name__ == "__main__":
app.run(debug=True, host = "0.0.0.0")
"""