update logging and set watch date on server side
This commit is contained in:
parent
ba3f916dcf
commit
8a5fba0f31
20
server.py
20
server.py
@ -15,6 +15,17 @@ logging.basicConfig(
|
|||||||
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
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
|
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
|
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_PASSWORD: str = os.getenv("MYSQL_PASSWORD", "your_password")
|
||||||
MYSQL_PORT: int = int(os.getenv("MYSQL_PORT", "3306"))
|
MYSQL_PORT: int = int(os.getenv("MYSQL_PORT", "3306"))
|
||||||
LOGLEVEL = os.getenv("LOGLEVEL", "INFO").strip().upper()
|
LOGLEVEL = os.getenv("LOGLEVEL", "INFO").strip().upper()
|
||||||
|
|
||||||
if LOGLEVEL == "DEBUG":
|
if LOGLEVEL == "DEBUG":
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
elif LOGLEVEL == "WARNING":
|
elif LOGLEVEL == "WARNING":
|
||||||
@ -39,9 +51,6 @@ else:
|
|||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get_mysql_connection():
|
def get_mysql_connection():
|
||||||
"""Get a MySQL database connection."""
|
"""Get a MySQL database connection."""
|
||||||
try:
|
try:
|
||||||
@ -120,10 +129,11 @@ def add_video():
|
|||||||
video_name: str = data.get("video_name")
|
video_name: str = data.get("video_name")
|
||||||
channel_url: str = data.get("channel_url")
|
channel_url: str = data.get("channel_url")
|
||||||
channel_name: str = data.get("channel_name")
|
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:
|
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
|
# Insert the data into the MySQL database
|
||||||
connection = get_mysql_connection()
|
connection = get_mysql_connection()
|
||||||
|
Loading…
Reference in New Issue
Block a user