Converted to package pattern
This commit is contained in:
parent
c4e4af5d59
commit
b3a4e6a95f
|
@ -0,0 +1,10 @@
|
||||||
|
from flask import Flask
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///static/db/database.db"
|
||||||
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
|
from core import routes
|
|
@ -0,0 +1,11 @@
|
||||||
|
from core import db
|
||||||
|
|
||||||
|
|
||||||
|
class Table(db.Model):
|
||||||
|
# title = db.Column(db.String, nullable=False)
|
||||||
|
# icon = db.Column(db.String, nullable=False)
|
||||||
|
# link = db.Column(db.String, nullable=False)
|
||||||
|
id = db.Column(db.Integer, nullable=False, primary_key=True, unique=True, autoincrement=True)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"['{self.title}', '{self.icon}', '{self.link}', '{self.id}']"
|
|
@ -1,13 +1,14 @@
|
||||||
|
from flask import request, render_template
|
||||||
|
from core import app, db # Get from __init__
|
||||||
|
|
||||||
|
from core.models import Table # Get db models
|
||||||
|
from core.MessageHandler import MessageHandler # Get simple message processor
|
||||||
|
|
||||||
|
|
||||||
# Python imports
|
# Python imports
|
||||||
from flask import Flask, request, render_template
|
|
||||||
|
|
||||||
# Application imports
|
|
||||||
from utils import DBConnect, MessageHandler
|
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
msgHandler = MessageHandler()
|
msgHandler = MessageHandler()
|
||||||
db = DBConnect()
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
|
@ -8,6 +8,6 @@
|
||||||
function main() {
|
function main() {
|
||||||
source "../bin/activate"
|
source "../bin/activate"
|
||||||
# Note can replace 127.0.0.1 with 0.0.0.0 to make it 'network/internet' accessable...
|
# Note can replace 127.0.0.1 with 0.0.0.0 to make it 'network/internet' accessable...
|
||||||
gunicorn app:app -b 127.0.0.1:8080 # <module>:<app> IE <file>:<flask app variable>
|
|
||||||
}
|
}
|
||||||
|
gunicorn wsgi:app -b 127.0.0.1:4040 # <module>:<app> IE <file>:<flask app variable>
|
||||||
main $@;
|
main $@;
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
import os, sqlite3
|
|
||||||
|
|
||||||
class DBConnect:
|
|
||||||
def __init__(self):
|
|
||||||
try:
|
|
||||||
self.db = None
|
|
||||||
self.conn = None
|
|
||||||
print("DBConnect initialized...")
|
|
||||||
except Exception as e:
|
|
||||||
print("Exception raised:")
|
|
||||||
print(e)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def createConnection(self):
|
|
||||||
self.db = sqlite3.connect('static/db/database.db')
|
|
||||||
self.conn = self.db.cursor()
|
|
||||||
|
|
||||||
def closeConnection(self):
|
|
||||||
self.conn.close()
|
|
||||||
|
|
||||||
|
|
||||||
def createEntry(self, args):
|
|
||||||
try:
|
|
||||||
# Example Insert
|
|
||||||
# sql = "INSERT INTO bills (Title, Amount, MoYr, Duedate, Optional) Values(?,?,?,?,?)";
|
|
||||||
# ps = (TITLE, float(AMOUNT), MOYR, DATE, OPTIONAL, )
|
|
||||||
self.conn.execute(sql, ps)
|
|
||||||
self.db.commit()
|
|
||||||
except Exception as e:
|
|
||||||
print("Exception raised:")
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
def updateEntry(self, args):
|
|
||||||
try:
|
|
||||||
# Example Update
|
|
||||||
# sql = "UPDATE bills SET Title = ?, Amount = ?, MoYr = ?, Duedate = ?, Optional = ? WHERE id = ?";
|
|
||||||
# ps = (TITLE, float(AMOUNT), MOYR, DATE, OPTIONAL, int(ID), )
|
|
||||||
self.conn.execute(sql, ps)
|
|
||||||
self.db.commit()
|
|
||||||
except Exception as e:
|
|
||||||
print("Exception raised:")
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
def deleteEntry(self, ID):
|
|
||||||
try:
|
|
||||||
# Example Delete
|
|
||||||
# sql = "DELETE FROM bills WHERE id = ?";
|
|
||||||
# ps = (int(ID), )
|
|
||||||
self.conn.execute(sql, ps)
|
|
||||||
self.db.commit()
|
|
||||||
except Exception as e:
|
|
||||||
print("Exception raised:")
|
|
||||||
print(e)
|
|
|
@ -1,2 +0,0 @@
|
||||||
from utils.DBConnect import DBConnect
|
|
||||||
from utils.MessageHandler import MessageHandler
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
from core import app
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
Loading…
Reference in New Issue