diff --git a/config.py b/config.py new file mode 100644 index 0000000..1cd97f8 --- /dev/null +++ b/config.py @@ -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() diff --git a/create_db.py b/create_db.py new file mode 100644 index 0000000..36f7860 --- /dev/null +++ b/create_db.py @@ -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) diff --git a/flask_app.py b/flask_app.py new file mode 100644 index 0000000..d29d9f9 --- /dev/null +++ b/flask_app.py @@ -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 = '' + 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 = "

ni zadetkov:
" + str(e) + "

" + hed = '

Komada ni v bazi.

' + return hed + error_text + +if __name__ == "__main__": + app.run(debug=True, host = "0.0.0.0")