Skip to content

Commit

Permalink
Merge pull request #15 from AtomsForPeace/refactor_app
Browse files Browse the repository at this point in the history
moved the creation of the app to the project init file. #14
  • Loading branch information
Impre-visible authored Apr 18, 2023
2 parents b2eed4b + 58f5e80 commit f7daa7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
17 changes: 4 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,17 @@
from pyarr import RadarrAPI, SonarrAPI, LidarrAPI, ReadarrAPI
from guessit import guessit

from chocolate import create_app, db, loginManager

start_time = mktime(localtime())

with warnings.catch_warnings():
warnings.simplefilter("ignore", category = sqlalchemy.exc.SAWarning)

app = Flask(__name__)
app.secret_key = "ChocolateDBPassword"

CORS(app, supports_credentials=True, resources={r"/*": {"origins": "*"}})
app = create_app()

dirPath = os.getcwd()
dirPath = os.path.dirname(__file__).replace("\\", "/")
app.config["SQLALCHEMY_DATABASE_URI"] = f'sqlite:///{dirPath}/database.db'
app.config['MAX_CONTENT_LENGTH'] = 4096 * 4096
app.config['UPLOAD_FOLDER'] = f"{dirPath}/static/img/"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
loginManager = LoginManager()
loginManager.init_app(app)
loginManager.login_view = 'login'
langs_dict = GoogleTranslator().get_supported_languages(as_dict=True)
allAuthTokens = {}

Expand Down Expand Up @@ -5077,4 +5068,4 @@ def downloadEpisode(episodeId):
for u in db.session.query(Series).all():
allSeriesDict[u.name] = u.__dict__

app.run(host="0.0.0.0", port="8888")
app.run(host="0.0.0.0", port="8888")
29 changes: 29 additions & 0 deletions chocolate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
from flask_login import LoginManager


db = SQLAlchemy()
loginManager = LoginManager()


def create_app():
app = Flask(__name__)
app.secret_key = "ChocolateDBPassword"

CORS(app, supports_credentials=True, resources={r"/*": {"origins": "*"}})

dirPath = os.getcwd()
dirPath = os.path.dirname(__file__).replace("\\", "/")
app.config["SQLALCHEMY_DATABASE_URI"] = f'sqlite:///{dirPath}/database.db'
app.config['MAX_CONTENT_LENGTH'] = 4096 * 4096
app.config['UPLOAD_FOLDER'] = f"{dirPath}/static/img/"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(app)
loginManager.init_app(app)
loginManager.login_view = 'login'

return app

0 comments on commit f7daa7e

Please sign in to comment.