-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15 - Fix linter use of duplicate code fragment
- Loading branch information
1 parent
80f33a4
commit 434f179
Showing
3 changed files
with
25 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
"""Main entry point for the application.""" | ||
|
||
from sys import path | ||
from os import getenv | ||
from dotenv import load_dotenv | ||
from sqlalchemy import URL | ||
from project import create_app_with_db | ||
from project.database import get_database_uri | ||
|
||
path.append(".") | ||
|
||
if __name__ == "__main__": | ||
load_dotenv() | ||
|
||
url = URL.create( | ||
drivername=getenv("DB_DRIVER"), | ||
username=getenv("DB_USER"), | ||
password=getenv("DB_PASSWORD"), | ||
host=getenv("DB_HOST"), | ||
port=int(getenv("DB_PORT")), | ||
database=getenv("DB_NAME") | ||
) | ||
|
||
app = create_app_with_db(url) | ||
app = create_app_with_db(get_database_uri()) | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
"""Database file""" | ||
|
||
from os import getenv | ||
from flask_sqlalchemy import SQLAlchemy | ||
from dotenv import load_dotenv | ||
from sqlalchemy import URL | ||
|
||
db = SQLAlchemy() | ||
|
||
def get_database_uri() -> str: | ||
"""Get the database URI made from environment variables | ||
Returns: | ||
str: Database URI | ||
""" | ||
load_dotenv() | ||
uri = URL.create( | ||
drivername=getenv("DB_DRIVER"), | ||
username=getenv("DB_USER"), | ||
password=getenv("DB_PASSWORD"), | ||
host=getenv("DB_HOST"), | ||
port=int(getenv("DB_PORT")), | ||
database=getenv("DB_NAME") | ||
) | ||
return uri |