fixed a small database issue with price drop tracking and added doc strings
This commit is contained in:
1 parent
a61dbdfaa9
commit
99d660ee52
6 files changed
+172
-4
No files matched your search
@@ -1,3 +1,5 @@
|
||||
"""Config loading and mode helpers shared across monitors and the bot."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import pathlib
|
||||
@@ -7,15 +9,19 @@ from monitor_utils.constants import DEVELOPMENT_BOT_TOKEN, LOGGERS, PRODUCTION_B
|
||||
|
||||
|
||||
class DevelopmentMode(str, Enum):
|
||||
"""Runtime mode selecting production or development behavior."""
|
||||
|
||||
PRODUCTION = "PRODUCTION"
|
||||
DEVELOPMENT = "DEVELOPMENT"
|
||||
|
||||
|
||||
def is_production(development_mode: DevelopmentMode) -> bool:
|
||||
"""Return True when the mode is PRODUCTION."""
|
||||
return development_mode == DevelopmentMode.PRODUCTION
|
||||
|
||||
|
||||
def get_bot_token(is_production: bool) -> str:
|
||||
"""Return the production or development bot token for the mode."""
|
||||
if is_production:
|
||||
return PRODUCTION_BOT_TOKEN
|
||||
|
||||
@@ -28,6 +34,17 @@ def get_config(
|
||||
test_config_dir: str | pathlib.Path = "tests/configs",
|
||||
use_production_path: bool = False,
|
||||
) -> tuple[dict, pathlib.Path]:
|
||||
"""Load a monitor's JSON config from the production or test directory.
|
||||
|
||||
Args:
|
||||
monitor_name: Monitor name with or without a .json suffix.
|
||||
config_dir: Directory holding production configs.
|
||||
test_config_dir: Directory holding test configs.
|
||||
use_production_path: Load from config_dir instead of test_config_dir.
|
||||
|
||||
Returns:
|
||||
Tuple of the parsed config dict and the resolved config path.
|
||||
"""
|
||||
monitor_name = monitor_name.replace(".json", "")
|
||||
base = config_dir if use_production_path else test_config_dir
|
||||
config_path = pathlib.Path(base) / f"{monitor_name}.json"
|
||||
@@ -36,5 +53,6 @@ def get_config(
|
||||
|
||||
|
||||
def set_logger_levels(loggers: list[str] = LOGGERS, level: int = logging.WARNING):
|
||||
"""Set the given loggers to the given level to quiet noisy libraries."""
|
||||
for name in loggers:
|
||||
logging.getLogger(name).setLevel(level)
|
||||
Reference in new issue
Block a user