small bug fix
This commit is contained in:
1 parent
cd8bc56871
commit
b02504e5f8
8 files changed
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import logging
|
||||
import json
|
||||
import pathlib
|
||||
from functools import cache
|
||||
from enum import Enum
|
||||
|
||||
from monitor_utils.src.constants import (
|
||||
PROXIES_PATH,
|
||||
PROJECT_ROOT,
|
||||
PRODUCTION_BOT_TOKEN,
|
||||
DEVELOPMENT_BOT_TOKEN,
|
||||
)
|
||||
|
||||
RESERVED = frozenset(logging.LogRecord("", 0, "", 0, "", (), None).__dict__)
|
||||
|
||||
|
||||
class DevelopmentMode(str, Enum):
|
||||
PRODUCTION = "PRODUCTION"
|
||||
DEVELOPMENT = "DEVELOPMENT"
|
||||
|
||||
|
||||
def is_production(development_mode: DevelopmentMode) -> bool:
|
||||
return development_mode == DevelopmentMode.PRODUCTION
|
||||
|
||||
|
||||
def get_bot_token(is_production: bool) -> str:
|
||||
if is_production:
|
||||
return PRODUCTION_BOT_TOKEN
|
||||
|
||||
return DEVELOPMENT_BOT_TOKEN
|
||||
|
||||
|
||||
@cache
|
||||
def get_proxies() -> list[str]:
|
||||
with PROXIES_PATH.open() as f:
|
||||
proxies = []
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
parts = line.split(":", 3)
|
||||
if len(parts) == 4 and not parts[1].startswith("//"):
|
||||
host, port, user, password = parts
|
||||
proxies.append(f"http://{user}:{password}@{host}:{port}")
|
||||
else:
|
||||
proxies.append(f"http://{line}")
|
||||
|
||||
if not proxies:
|
||||
raise ValueError("Proxy list cannot be empty")
|
||||
|
||||
return proxies
|
||||
|
||||
|
||||
def get_config(
|
||||
monitor_name: str, use_production_path: bool = False
|
||||
) -> tuple[dict, pathlib.Path]:
|
||||
monitor_name = monitor_name.replace(".json", "")
|
||||
if use_production_path:
|
||||
config_path = PROJECT_ROOT / "configs" / f"{monitor_name}.json"
|
||||
else:
|
||||
config_path = PROJECT_ROOT / "tests" / "configs" / f"{monitor_name}.json"
|
||||
|
||||
with open(config_path) as f:
|
||||
return json.load(f), config_path
|
||||
Reference in new issue
Block a user