From 8a5fba0f31ecc0ff1215aea519578e7ef838dc47 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Thu, 5 Sep 2024 04:34:23 -0700 Subject: [PATCH] update logging and set watch date on server side --- server.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 0b89889..0c32f9e 100755 --- a/server.py +++ b/server.py @@ -15,6 +15,17 @@ logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) +# Ensure Flask doesn't duplicate log messages +log = logging.getLogger("werkzeug") +log.setLevel(logging.ERROR) + +# Flask app +app = Flask(__name__) + +# Flask logging configuration to use the same logger as the rest of the app +app.logger.handlers = logging.getLogger().handlers +app.logger.setLevel(logging.getLogger().level) + SOCKET_RETRY_DELAY = 5 # Time in seconds between retries to connect to the socket MAX_RETRIES = 10 # Maximum number of retries to connect to the socket @@ -29,6 +40,7 @@ MYSQL_USER: str = os.getenv("MYSQL_USER", "your_username") MYSQL_PASSWORD: str = os.getenv("MYSQL_PASSWORD", "your_password") MYSQL_PORT: int = int(os.getenv("MYSQL_PORT", "3306")) LOGLEVEL = os.getenv("LOGLEVEL", "INFO").strip().upper() + if LOGLEVEL == "DEBUG": logging.getLogger().setLevel(logging.DEBUG) elif LOGLEVEL == "WARNING": @@ -39,9 +51,6 @@ else: logging.getLogger().setLevel(logging.INFO) -app = Flask(__name__) - - def get_mysql_connection(): """Get a MySQL database connection.""" try: @@ -120,10 +129,11 @@ def add_video(): video_name: str = data.get("video_name") channel_url: str = data.get("channel_url") channel_name: str = data.get("channel_name") - watch_date: date = data.get("watch_date") + watch_date: date = date.today().strftime("%Y-%m-%d") if video_url and video_name and channel_url and channel_name and watch_date: - logging.info(f"Received data: {data}") + logging.debug(f"Received data: {data}") + logging.debug(f"Watch date: {watch_date}") # Insert the data into the MySQL database connection = get_mysql_connection()