From 914e8f9ce8c0b63537d831fe2f7128df4f18efaf Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 31 Jul 2025 19:37:08 -0600 Subject: [PATCH] refactor: Move secrets to module and improve logging config --- server.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index adf820b..e24e7c7 100644 --- a/server.py +++ b/server.py @@ -1,8 +1,13 @@ +import os, logging +DEBUG = os.environ.get('DEBUG') +logging.basicConfig( + format='[%(asctime)s] %(levelname)s %(module)s/%(funcName)s - %(message)s', + level=logging.DEBUG if DEBUG else logging.INFO) +logging.getLogger('aiohttp').setLevel(logging.DEBUG if DEBUG else logging.WARNING) + import asyncio import aiohttp from aiohttp import web -import logging -import os import io from datetime import datetime @@ -11,16 +16,13 @@ import torch.nn.functional as F from torchvision import transforms from PIL import Image +import mysecrets from model import (CropLowerRightTriangle, GarageDoorCNN, TRIANGLE_CROP_WIDTH, TRIANGLE_CROP_HEIGHT, RESIZE_DIM) # --- Configuration --- logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') -BLUEIRIS_KEY = os.getenv('BLUEIRIS_KEY') -if not BLUEIRIS_KEY: - raise ValueError("BLUEIRIS_KEY environment variable not set.") - CAMERA_URL = "http://cameras.dns.t0.vc/image/SE-S?&w=9999&decode=1" MODEL_PATH = 'garage_door_cnn.pth' CLASS_NAMES = ['closed', 'open'] # From training, sorted alphabetically @@ -62,7 +64,7 @@ async def monitor_garage_door(app): session = app['client_session'] model = app['model'] device = app['device'] - headers = {'Authorization': 'Basic ' + BLUEIRIS_KEY} + headers = {'Authorization': 'Basic ' + mysecrets.BLUEIRIS_KEY} while True: try: