refactor: Move secrets to module and improve logging config
This commit is contained in:
16
server.py
16
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 asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import io
|
import io
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -11,16 +16,13 @@ import torch.nn.functional as F
|
|||||||
from torchvision import transforms
|
from torchvision import transforms
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
import mysecrets
|
||||||
from model import (CropLowerRightTriangle, GarageDoorCNN, TRIANGLE_CROP_WIDTH,
|
from model import (CropLowerRightTriangle, GarageDoorCNN, TRIANGLE_CROP_WIDTH,
|
||||||
TRIANGLE_CROP_HEIGHT, RESIZE_DIM)
|
TRIANGLE_CROP_HEIGHT, RESIZE_DIM)
|
||||||
|
|
||||||
# --- Configuration ---
|
# --- Configuration ---
|
||||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
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"
|
CAMERA_URL = "http://cameras.dns.t0.vc/image/SE-S?&w=9999&decode=1"
|
||||||
MODEL_PATH = 'garage_door_cnn.pth'
|
MODEL_PATH = 'garage_door_cnn.pth'
|
||||||
CLASS_NAMES = ['closed', 'open'] # From training, sorted alphabetically
|
CLASS_NAMES = ['closed', 'open'] # From training, sorted alphabetically
|
||||||
@@ -62,7 +64,7 @@ async def monitor_garage_door(app):
|
|||||||
session = app['client_session']
|
session = app['client_session']
|
||||||
model = app['model']
|
model = app['model']
|
||||||
device = app['device']
|
device = app['device']
|
||||||
headers = {'Authorization': 'Basic ' + BLUEIRIS_KEY}
|
headers = {'Authorization': 'Basic ' + mysecrets.BLUEIRIS_KEY}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user