From 949086d60554cdf30af48738b61e978a82ee3508 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Wed, 18 Mar 2020 10:59:37 +0100 Subject: [PATCH] initial commit --- .gitignore | 5 +++++ config.py | 10 ++++++++++ oshipka.py | 7 +++++++ persistance/__init__.py | 0 persistance/models.py | 8 ++++++++ persistance/populate.py | 22 ++++++++++++++++++++++ requirements.txt | 8 ++++++++ webapp/__init__.py | 4 ++++ 8 files changed, 64 insertions(+) create mode 100644 .gitignore create mode 100644 config.py create mode 100644 oshipka.py create mode 100644 persistance/__init__.py create mode 100644 persistance/models.py create mode 100644 persistance/populate.py create mode 100644 requirements.txt create mode 100644 webapp/__init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c40623 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +venv +*.pyc +data/db.sqlite +__pycache__ \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..d88d0b1 --- /dev/null +++ b/config.py @@ -0,0 +1,10 @@ +import os + +basepath = os.path.dirname(os.path.realpath(__file__)) + +DATA_DIR = os.path.join(basepath, "data") +DATABASE_FILE = os.path.join(DATA_DIR, "db.sqlite") +SQLALCHEMY_DATABASE_URI = 'sqlite:///{}'.format(DATABASE_FILE) +MAKEDIRS = [ + DATA_DIR, +] diff --git a/oshipka.py b/oshipka.py new file mode 100644 index 0000000..50adb87 --- /dev/null +++ b/oshipka.py @@ -0,0 +1,7 @@ +from persistance.populate import init_db +from webapp import app + +if __name__ == "__main__": + init_db(app) + + app.run(debug=True) diff --git a/persistance/__init__.py b/persistance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/persistance/models.py b/persistance/models.py new file mode 100644 index 0000000..61e2559 --- /dev/null +++ b/persistance/models.py @@ -0,0 +1,8 @@ +import json +import os + +from flask import render_template, request +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy_utils import ChoiceType + +db = SQLAlchemy() \ No newline at end of file diff --git a/persistance/populate.py b/persistance/populate.py new file mode 100644 index 0000000..93f2830 --- /dev/null +++ b/persistance/populate.py @@ -0,0 +1,22 @@ +import os + +from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE +from persistance.models import db + + +def populate_db(app): + with app.app_context(): + pass + + +def init_db(app): + app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + + db.init_app(app) + for dir in MAKEDIRS: + os.makedirs(dir, exist_ok=True) + if not os.path.exists(DATABASE_FILE): + with app.app_context(): + db.create_all() + populate_db(app) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8f8c054 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +click==7.1.1 +Flask==1.1.1 +Flask-SQLAlchemy==2.4.1 +itsdangerous==1.1.0 +Jinja2==2.11.1 +MarkupSafe==1.1.1 +SQLAlchemy==1.3.15 +Werkzeug==1.0.0 diff --git a/webapp/__init__.py b/webapp/__init__.py new file mode 100644 index 0000000..5a43827 --- /dev/null +++ b/webapp/__init__.py @@ -0,0 +1,4 @@ +from flask import Flask + +app = Flask(__name__) +app.config["SECRET_KEY"] = "UNSECRET_KEY....478932fjkdsl"