From 1f577c04bdd9a222fdf77731f3a87a10affdc637 Mon Sep 17 00:00:00 2001 From: gwen Date: Thu, 14 Sep 2023 18:03:46 +0200 Subject: [PATCH] add config.py --- .gitignore | 2 +- app/config.py | 19 +++++++++++++++++++ app/routes.py | 12 ++++++------ requirements.txt | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/config.py diff --git a/.gitignore b/.gitignore index 29eeee3..e6b4e53 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .venv/* - +params.yaml diff --git a/app/config.py b/app/config.py new file mode 100644 index 0000000..5775352 --- /dev/null +++ b/app/config.py @@ -0,0 +1,19 @@ +"""Application's configuration file""" + +from pathlib import Path + +# path configuration +# let's guess that :file:`config.py` is located here : :file:`{rootpath}/webapp/` +_here = Path(__file__).resolve().parent + +rootpath = _here.parent +"root project directory" + +from yaml import safe_load + +# loads database credentials +local_params_file = rootpath / "params.yaml" +with open(local_params_file, 'r') as file_handle: + params_content = safe_load(file_handle) + dbadmin = params_content['dbadmin'] + dbpassword = params_content['dbpassword'] diff --git a/app/routes.py b/app/routes.py index f4d5dc5..7eaa67c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,15 +1,15 @@ import typing as t +import urllib.parse from flask import Blueprint, abort, render_template, request, send_from_directory - -main = Blueprint("main", __name__, url_prefix="/") - from pymongo import MongoClient -import urllib.parse +from .config import dbadmin, dbpassword + +main = Blueprint("main", __name__, url_prefix="/") -username = urllib.parse.quote_plus('dbadmin') -password = urllib.parse.quote_plus('BrOp48la%Mrops') +username = urllib.parse.quote_plus(dbadmin) +password = urllib.parse.quote_plus(dbpassword) myclient = MongoClient('mongodb://%s:%s@149.202.41.75:27017' % (username, password)) mydb = myclient["actesdb"] dbhouse = mydb["house"] diff --git a/requirements.txt b/requirements.txt index cc364e7..88a7665 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,5 @@ Werkzeug==2.3.7 Flask-WTF==1.1.1 WTForms==3.0.1 zipp==3.9.0 +pyyaml-6.0.1 +