ustvaril file po muštru

master
Kostanjevec 2022-04-23 22:55:51 +02:00
parent 513f560b20
commit ced983d5ed
3 changed files with 103 additions and 0 deletions

16
config.py 100644
View File

@ -0,0 +1,16 @@
#!/usr/bin/python3
import os
config_file = '.env.dist'
if os.path.isfile('.env'):
config_file = '.env'
CONFIG = {}
vsebina = []
with open(config_file) as cf:
vsebina = cf.readlines()
for vrstica in vsebina:
key, val = vrstica.split('=', 1)
CONFIG[key] = val.rstrip()

23
create_db.py 100644
View File

@ -0,0 +1,23 @@
#!/usr/bin/python3
from sqlalchemy import Column, Integer, Float, String, Text, TIMESTAMP,ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import func, create_engine,join
from config import CONFIG
Base = declarative_base()
class USER(Base):
class Item(Base):
class Interest(Base):
engine = create_engine(CONFIG['DB_CONNECTION'])
Base.metadata.create_all(engine)

64
flask_app.py 100644
View File

@ -0,0 +1,64 @@
#!/usr/bin/python3
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 = Flask(__name__)
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")