Skip to content

Commit

Permalink
Filepaths revamped
Browse files Browse the repository at this point in the history
  • Loading branch information
OperaVaria committed Jul 11, 2024
1 parent a43db32 commit 1707d96
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions serotonin_flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@
from config.settings import csp # Content security policy settings.
from config.settings import bypass # Minify bypass settings.

# Create absolute paths.
config_path = Path(__file__).parents[0].resolve() / "config"
data_path = Path(__file__).parents[0].resolve() / "data"
# Create path constants.
PROJECT_DIR_PATH = Path(__file__).parents[0].resolve()
CONFIG_DIR_PATH = (PROJECT_DIR_PATH).joinpath("config/")
DATA_DIR_PATH = (PROJECT_DIR_PATH).joinpath("data/")
SECRET_KEY_PATH = (CONFIG_DIR_PATH).joinpath("secretKey.json")
SETTINGS_FILE_PATH = (CONFIG_DIR_PATH).joinpath("settings.py")

# Create Flask app.
app = Flask(__name__)

# Flask app configuration:
app.config.from_file(f"{config_path}/secretKey.json", load=json.load) # Load secret key.
app.config.from_pyfile(f"{config_path}/settings.py") # Load other settings.
app.config.from_file(SECRET_KEY_PATH, load=json.load) # Load secret key.
app.config.from_pyfile(SETTINGS_FILE_PATH) # Load other settings.

# Set up Talisman. Force HTTPS should normally be on, but Cloudflare handles it.
tali = Talisman(app, content_security_policy=csp, force_https=False)
Expand Down Expand Up @@ -119,9 +122,10 @@ def result(animal):
session["exceptPool"] = []
# Create secure pickle file path, load post from pickled list, excluding exceptPool.
# If out of posts, display error page.
pickle_file = secure_filename(f"{data_path}/{animal}_data.p")
file_name = secure_filename(f"{animal}_data.p")
pickle_file_path = (DATA_DIR_PATH).joinpath(file_name)
try:
post = load_from_pickle(pickle_file, session.get("exceptPool"))
post = load_from_pickle(pickle_file_path, session.get("exceptPool"))
except IndexError:
return render_template("no-post.html", current_year=current_year, title_var=animal_title,
animal_var=animal_var, version=__version__)
Expand Down

0 comments on commit 1707d96

Please sign in to comment.