Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,36 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import logging
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
# Logging-Konfiguration
|
| 8 |
setup_logging()
|
| 9 |
|
| 10 |
-
if
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
app.py (verbessert)
|
| 2 |
+
|
| 3 |
+
import asyncio import logging from scheduler import start_scheduler from config import setup_logging
|
| 4 |
+
|
| 5 |
+
Logging-Konfiguration
|
| 6 |
|
|
|
|
| 7 |
setup_logging()
|
| 8 |
|
| 9 |
+
if name == "main": try: start_scheduler() loop = asyncio.get_event_loop() loop.run_forever() except KeyboardInterrupt: logging.info("Bot wurde beendet") except Exception as e: logging.error(f"Kritischer Fehler: {str(e)}")
|
| 10 |
+
|
| 11 |
+
config.py (verbessert)
|
| 12 |
+
|
| 13 |
+
import json import os import logging from pathlib import Path
|
| 14 |
+
|
| 15 |
+
Pfade
|
| 16 |
+
|
| 17 |
+
BASE_DIR = Path(file).parent CONFIG_DIR = BASE_DIR / "config" FEEDS_FILE = CONFIG_DIR / "feeds.json" API_KEYS_FILE = CONFIG_DIR / "api_keys.json" BLACKLIST_FILE = CONFIG_DIR / "blacklist.txt" WHITELIST_FILE = CONFIG_DIR / "whitelist.txt"
|
| 18 |
+
|
| 19 |
+
Logging-Konfiguration
|
| 20 |
+
|
| 21 |
+
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() ] )
|
| 22 |
+
|
| 23 |
+
Konfigurationsladefunktionen
|
| 24 |
+
|
| 25 |
+
def load_json(file_path): try: with open(file_path, "r", encoding="utf-8") as f: return json.load(f) except FileNotFoundError: logging.error(f"Datei nicht gefunden: {file_path}") return {}
|
| 26 |
+
|
| 27 |
+
def load_text_list(file_path): try: with open(file_path, "r", encoding="utf-8") as f: return [line.strip().lower() for line in f if line.strip()] except FileNotFoundError: logging.warning(f"Datei nicht gefunden: {file_path}") return []
|
| 28 |
+
|
| 29 |
+
Laden der Konfiguration
|
| 30 |
+
|
| 31 |
+
FEEDS = load_json(FEEDS_FILE) API_KEYS = load_json(API_KEYS_FILE) BLACKLIST = load_text_list(BLACKLIST_FILE) WHITELIST = load_text_list(WHITELIST_FILE)
|
| 32 |
+
|
| 33 |
+
SETTINGS = { "check_interval": 5, "max_retries": 3, "request_timeout": 10, "max_articles": 50, "telegram_chat_id": API_KEYS.get("telegram_chat_id", ""), "telegram_bot_token": API_KEYS.get("telegram_bot_token", "") }
|
| 34 |
+
|
| 35 |
+
CATEGORY_FILTERS = { "technology": ["AI", "Machine Learning", "Cybersecurity"], "politics": ["Election", "Government", "Policy"] }
|
| 36 |
+
|