Compare commits

...

3 Commits

Author SHA1 Message Date
Kostanjevec 9229489221 worked on db etc 2022-04-25 00:32:17 +02:00
Kostanjevec ced983d5ed ustvaril file po muštru 2022-04-23 22:55:51 +02:00
Kostanjevec 513f560b20 comment 2022-04-21 19:07:44 +02:00
11 changed files with 188 additions and 1 deletions

12
.gitignore vendored
View File

@ -138,3 +138,15 @@ dmypy.json
# Cython debug symbols
cython_debug/
*.pyc
__pycache__/
instance/
.pytest_cache/
.coverage
htmlcov/
dist/
build/
*.egg-info/

View File

@ -1,3 +1,4 @@
# contentmatches
blabla
bla
blabla

32
app/__init__.py 100644
View File

@ -0,0 +1,32 @@
import os
from flask import Flask
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
# a simple page that says hello
@app.route('/hello')
def hello():
return 'Hello, Woooorld!'
return app

77
app/app.py 100644
View File

@ -0,0 +1,77 @@
#!/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")
"""

0
app/auth.py 100644
View File

View File

View File

View File

View File

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()

49
create_db.py 100644
View File

@ -0,0 +1,49 @@
#!/usr/bin/python3
from csv import unregister_dialect
import email
from sqlite3 import Date
from ssl import _PasswordType
from xmlrpc.client import DateTime
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):
__tablename__ = 'user'
id = Column(Integer, primary_key=True, autoincrement=True)
username = Column(String)
password = Column(String) #mogoče raje kaj drugega, neki hash passworda al neki
email = Column(String)
class Item(Base):
__tablename__ = 'item'
id = Column(Integer, primary_key=True, autoincrement=True)
owner_id = Column(String, ForeignKey("user.id"), nullable=False)
item_location = Column(String)
item_type = Column(String)
item_size = Column(Integer)
class Interest(Base):
__tablename__ = 'interest'
pdf_id = Column(String, ForeignKey("item.id"), nullable=False)
user_id = Column(String, ForeignKey("user.id"), nullable=False)
interest_rate = Column(Float)
#ali
# date_added = Column(String)
# last_review = Column(DateTime)
# interval = Column(Integer)
# due = Column(DateTime)
engine = create_engine(CONFIG['DB_CONNECTION'])
Base.metadata.create_all(engine)