Add .env file for configuration, update db connection to use environment variables, and enhance requirements
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
#database
|
||||||
|
DB_NAME="canada_luggage"
|
||||||
|
#Credentials
|
||||||
|
DB_PASSWORD="13579,QsC"
|
||||||
|
DB_USER="luggage"
|
||||||
|
#Host Settings
|
||||||
|
DB_PORT="3307"
|
||||||
|
DB_HOST="192.168.1.74"
|
||||||
@@ -2,7 +2,6 @@ import mariadb
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Logging
|
#Logging
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -18,14 +17,14 @@ except Exception as e:
|
|||||||
logging.exception('An error occurred')
|
logging.exception('An error occurred')
|
||||||
|
|
||||||
|
|
||||||
def connect():
|
def connect(db_user, db_psswd, db_host, db_port, db_name):
|
||||||
try:
|
try:
|
||||||
global connection
|
global connection
|
||||||
connection = mariadb.connect(user="luggage",
|
connection = mariadb.connect(user=db_user,
|
||||||
password="13579,QsC",
|
password=db_psswd,
|
||||||
host="192.168.1.74",
|
host=db_host,
|
||||||
port=3307,
|
port=db_port,
|
||||||
database="canada_luggage")
|
database=db_name)
|
||||||
print("Connected to MariaDB successfully!")
|
print("Connected to MariaDB successfully!")
|
||||||
logging.info("Connected to MariaDB successfully!")
|
logging.info("Connected to MariaDB successfully!")
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,24 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
|
||||||
|
#using .env
|
||||||
|
load_dotenv()
|
||||||
|
db_name = os.getenv("DB_NAME")
|
||||||
|
db_psswd = os.getenv("DB_PASSWORD")
|
||||||
|
db_user = os.getenv("DB_USER")
|
||||||
|
db_port = os.getenv("DB_PORT") or "3306"
|
||||||
|
db_host = os.getenv("DB_HOST")
|
||||||
|
if db_host == None:
|
||||||
|
logging.error("no hostname provided")
|
||||||
|
os._exit(1)
|
||||||
|
|
||||||
|
|
||||||
print("loading")
|
print("loading")
|
||||||
open("app.log", "w").close()
|
open("app.log", "w").close()
|
||||||
db.connect()
|
db.connect(db_user, db_psswd, db_host, int(db_port), db_name)
|
||||||
#Logging
|
#Logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename='app.log', # Log to a file
|
filename='app.log', # Log to a file
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
mariadb == 1.1.14
|
mariadb == 1.1.14
|
||||||
|
python-dotenv == 1.2.3
|
||||||
Reference in New Issue
Block a user