refactor: apply consistent formatting and improve code readability across backend modules

This commit is contained in:
2025-08-01 22:51:38 +02:00
parent 0fd2c7a8b6
commit e1f51794af
5 changed files with 147 additions and 65 deletions

View File

@@ -1,6 +1,6 @@
from pathlib import Path
import os
import logging
import os
from pathlib import Path
DB_PATH = Path(os.getenv("DB_NAME", "owlynews.sqlite3"))
OLLAMA_HOST = os.getenv("OLLAMA_HOST", "http://localhost:11434")
@@ -42,7 +42,8 @@ def update_constants_from_db(settings_dict):
if 'ollama_host' in settings_dict and os.getenv("OLLAMA_HOST") is None:
OLLAMA_HOST = settings_dict['ollama_host']
if 'min_cron_hours' in settings_dict and os.getenv("MIN_CRON_HOURS") is None:
if 'min_cron_hours' in settings_dict and os.getenv(
"MIN_CRON_HOURS") is None:
try:
MIN_CRON_HOURS = float(settings_dict['min_cron_hours'])
except (ValueError, TypeError):
@@ -61,7 +62,8 @@ def update_constants_from_db(settings_dict):
f"{settings_dict['cron_hours']}"
)
if 'sync_cooldown_minutes' in settings_dict and os.getenv("SYNC_COOLDOWN_MINUTES") is None:
if 'sync_cooldown_minutes' in settings_dict and os.getenv(
"SYNC_COOLDOWN_MINUTES") is None:
try:
SYNC_COOLDOWN_MINUTES = int(settings_dict['sync_cooldown_minutes'])
except (ValueError, TypeError):
@@ -73,7 +75,8 @@ def update_constants_from_db(settings_dict):
if 'llm_model' in settings_dict and os.getenv("LLM_MODEL") is None:
LLM_MODEL = settings_dict['llm_model']
if 'llm_timeout_seconds' in settings_dict and os.getenv("LLM_TIMEOUT_SECONDS") is None:
if 'llm_timeout_seconds' in settings_dict and os.getenv(
"LLM_TIMEOUT_SECONDS") is None:
try:
LLM_TIMEOUT_SECONDS = int(settings_dict['llm_timeout_seconds'])
except (ValueError, TypeError):
@@ -82,16 +85,19 @@ def update_constants_from_db(settings_dict):
f"{settings_dict['llm_timeout_seconds']}"
)
if 'ollama_api_timeout_seconds' in settings_dict and os.getenv("OLLAMA_API_TIMEOUT_SECONDS") is None:
if 'ollama_api_timeout_seconds' in settings_dict and os.getenv(
"OLLAMA_API_TIMEOUT_SECONDS") is None:
try:
OLLAMA_API_TIMEOUT_SECONDS = int(settings_dict['ollama_api_timeout_seconds'])
OLLAMA_API_TIMEOUT_SECONDS = int(
settings_dict['ollama_api_timeout_seconds'])
except (ValueError, TypeError):
logger.warning(
f"⚠️ Invalid ollama_api_timeout_seconds value in DB: "
f"{settings_dict['ollama_api_timeout_seconds']}"
)
if 'article_fetch_timeout' in settings_dict and os.getenv("ARTICLE_FETCH_TIMEOUT") is None:
if 'article_fetch_timeout' in settings_dict and os.getenv(
"ARTICLE_FETCH_TIMEOUT") is None:
try:
ARTICLE_FETCH_TIMEOUT = int(settings_dict['article_fetch_timeout'])
except (ValueError, TypeError):
@@ -100,7 +106,8 @@ def update_constants_from_db(settings_dict):
f"{settings_dict['article_fetch_timeout']}"
)
if 'max_article_length' in settings_dict and os.getenv("MAX_ARTICLE_LENGTH") is None:
if 'max_article_length' in settings_dict and os.getenv(
"MAX_ARTICLE_LENGTH") is None:
try:
MAX_ARTICLE_LENGTH = int(settings_dict['max_article_length'])
except (ValueError, TypeError):