|
|
|
import json |
|
import os |
|
import logging |
|
from pathlib import Path |
|
from typing import Dict, List, Union |
|
|
|
|
|
BASE_DIR = Path(__file__).parent |
|
CONFIG_DIR = BASE_DIR / "config" |
|
FEEDS_FILE = CONFIG_DIR / "feeds.json" |
|
API_KEYS_FILE = CONFIG_DIR / "api_keys.json" |
|
|
|
|
|
def setup_logging(): |
|
logging.basicConfig( |
|
level=logging.INFO, |
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", |
|
handlers=[ |
|
logging.FileHandler("news_bot.log"), |
|
logging.StreamHandler() |
|
] |
|
) |
|
logging.getLogger("apscheduler").setLevel(logging.WARNING) |
|
|
|
|
|
def load_feeds() -> List[Dict]: |
|
with open(FEEDS_FILE) as f: |
|
return json.load(f) |
|
|
|
def load_api_keys() -> Dict[str, str]: |
|
try: |
|
with open(API_KEYS_FILE) as f: |
|
return json.load(f) |
|
except FileNotFoundError: |
|
logging.warning("API-Keys-Datei nicht gefunden!") |
|
return {} |
|
|
|
|
|
SETTINGS = { |
|
"check_interval": 5, |
|
"max_retries": 3, |
|
"request_timeout": 10, |
|
"max_articles": 50, |
|
"telegram_chat_id": "", |
|
"telegram_bot_token": "", |
|
"newsapi_page_size": 100 |
|
} |
|
|
|
|
|
CATEGORY_FILTERS = { |
|
"technology": ["AI", "Machine Learning", "Cybersecurity"], |
|
"politics": ["Election", "Government", "Policy"] |
|
} |