Skip to content

Commit

Permalink
chore: quick fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Dijoux committed Oct 26, 2023
1 parent 611db74 commit dcf0ff2
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 251 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ secure = "==0.3.0"
[dev-packages]

[requires]
python_version = "3.10"
python_version = "3.11"
615 changes: 381 additions & 234 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/formation/data.json

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
load_dotenv()


def get_dev_db_uri() -> str:
return "sqlite:///onisepapi.db"


def get_prod_db_uri() -> str:
def get_db_uri() -> str:
username = os.environ.get("DATABASE_USERNAME")
password = os.environ.get("DATABASE_PASSWORD")
host = os.environ.get("DATABASE_HOST")
return f"mysql+mysqlconnector://{str(username)}:{str(password)}@{str(host)}/onisep?charset=utf8mb4&collation=utf8mb4_general_ci"
port = os.environ.get("PORT")
return f"mysql+mysqlconnector://{str(username)}:{str(password)}@{str(host)}:{str(port)}/onisep?charset=utf8mb4&collation=utf8mb4_general_ci"


class Config(object):
Expand All @@ -29,12 +26,12 @@ class Config(object):

class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = get_prod_db_uri()
SQLALCHEMY_DATABASE_URI = get_db_uri()


class ProductionConfig(Config):
DEBUG = False
SQLALCHEMY_DATABASE_URI = get_prod_db_uri()
SQLALCHEMY_DATABASE_URI = get_db_uri()
SQLALCHEMY_ENGINE_OPTIONS = {
"pool_pre_ping": True,
"pool_recycle": 300,
Expand Down
8 changes: 4 additions & 4 deletions src/blueprints/formations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
formations = Blueprint("formations", __name__, url_prefix="/api/v1/formations")


def filter_by_link(formations: list[dict[str, Any]], id: str) -> dict[str, Any]:
filtered_list = list(filter(lambda f: f["identifiant"] == id, formations))
def filter_by_link(formations: list[dict[str, Any]], for_id: str) -> dict[str, Any]:
filtered_list = list(filter(lambda f: f["identifiant"] == for_id, formations))
return filtered_list[0] if filtered_list else {}


Expand All @@ -25,6 +25,6 @@ def get_formation_by_id(id: str) -> Tuple[Response, int] | HTTPException:
with open("assets/formation/data.json", "r") as json_file:
result = filter_by_link(json.load(json_file)["formations"]["formation"], id)
return jsonify(result), HTTP_200_OK if len(result) > 0 else HTTP_200_OK
except Exception:
print("Error in get_formation_by_id : ", Exception)
except Exception as e:
print("Error in get_formation_by_id : ", str(e))
abort(HTTP_500_INTERNAL_SERVER_ERROR)
6 changes: 3 additions & 3 deletions utils/get_formations_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def extract_xml(response: requests.Response) -> dict:
def convert_to_xml_to_json(xml: dict) -> bool:
json_data = json.dumps(xml)
filename = "data.json"
path = "assets/formation/"
path = "../assets/formation/"
try:
with open(path + filename, "w") as json_file:
json_file.write(json_data)
Expand All @@ -35,8 +35,8 @@ def convert_to_xml_to_json(xml: dict) -> bool:
)
)
return True
except Exception:
logging.debug(f"Error in convert : {Exception}")
except Exception as e:
logging.debug(f"Error in convert : {str(e)}")
return False


Expand Down

0 comments on commit dcf0ff2

Please sign in to comment.