diff --git a/app/__pycache__/app.cpython-39.pyc b/app/__pycache__/app.cpython-39.pyc index b8a2778..c266257 100644 Binary files a/app/__pycache__/app.cpython-39.pyc and b/app/__pycache__/app.cpython-39.pyc differ diff --git a/app/__pycache__/config.cpython-39.pyc b/app/__pycache__/config.cpython-39.pyc index 0dae9cc..b501875 100644 Binary files a/app/__pycache__/config.cpython-39.pyc and b/app/__pycache__/config.cpython-39.pyc differ diff --git a/app/app.py b/app/app.py index 55a4b2b..7582ba2 100644 --- a/app/app.py +++ b/app/app.py @@ -2,16 +2,20 @@ from flask import Flask, redirect, url_for, render_template from views.index_views import index from views.user_views import user from views.group_views import group -from config import app_config +from config import app_config as config_class from database import init_app import logging, os from logging.handlers import RotatingFileHandler +# Instantiate config class +app_config = config_class() + app = Flask(__name__) app.config.from_object(app_config) init_app(app) +# Logging if app.config.get('LOG_TO_FILE'): log_file = app.config.get('LOG_FILE_PATH', '/app/logs/app.log') os.makedirs(os.path.dirname(log_file), exist_ok=True) diff --git a/app/config.py b/app/config.py index d42f9d7..9a68f39 100644 --- a/app/config.py +++ b/app/config.py @@ -16,9 +16,14 @@ class Config: OUI_API_LIMIT_PER_SEC = int(os.getenv('OUI_API_LIMIT_PER_SEC', '2')) OUI_API_DAILY_LIMIT = int(os.getenv('OUI_API_DAILY_LIMIT', '10000')) - # Timezone - APP_TIMEZONE = os.getenv('APP_TIMEZONE', 'UTC') - TZ = pytz.timezone(APP_TIMEZONE) + # These get set in __init__ + APP_TIMEZONE = 'UTC' + TZ = pytz.utc + + def __init__(self): + tz_name = os.getenv('APP_TIMEZONE', 'UTC') + self.APP_TIMEZONE = tz_name + self.TZ = pytz.timezone(tz_name) class DevelopmentConfig(Config): """Development configuration.""" diff --git a/app/views/__pycache__/index_views.cpython-39.pyc b/app/views/__pycache__/index_views.cpython-39.pyc index 8b2c79d..3b3f967 100644 Binary files a/app/views/__pycache__/index_views.cpython-39.pyc and b/app/views/__pycache__/index_views.cpython-39.pyc differ diff --git a/app/views/index_views.py b/app/views/index_views.py index 345589a..0ad67d8 100644 --- a/app/views/index_views.py +++ b/app/views/index_views.py @@ -1,23 +1,31 @@ from flask import Blueprint, render_template, request, jsonify from database import get_db -from pytz import timezone from datetime import datetime -import requests +import requests, pytz index = Blueprint('index', __name__) OUI_API_URL = 'https://api.maclookup.app/v2/macs/{}' +import pytz # make sure it's imported if not already + def time_ago(dt): - from config import LOCAL_TZ + if not dt: + return "n/a" + + tz_name = current_app.config.get('APP_TIMEZONE', 'UTC') + local_tz = current_app.config.get('TZ', pytz.utc) + + # Only assign UTC tzinfo if naive if dt.tzinfo is None: - dt = dt.replace(tzinfo=pytz.UTC) - local_dt = dt.astimezone(LOCAL_TZ) + dt = dt.replace(tzinfo=pytz.utc) + + # Convert to app timezone + dt = dt.astimezone(local_tz) + now = datetime.now(local_tz) + diff = now - dt - now = datetime.now(LOCAL_TZ) - diff = now - local_dt seconds = int(diff.total_seconds()) - if seconds < 60: return f"{seconds}s ago" elif seconds < 3600: @@ -28,6 +36,7 @@ def time_ago(dt): return f"{seconds//86400}d{(seconds%86400)//3600}h ago" + def lookup_vendor(mac): prefix = mac.replace(":", "").replace("-", "").upper()[:6] db = get_db()