Dunevhhhh commited on
Commit
f61e19a
·
verified ·
1 Parent(s): 8e8c527

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -33
app.py CHANGED
@@ -1,36 +1,24 @@
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
-
 
1
+ # app.py
2
+ import asyncio
3
+ import logging
4
+ from scheduler import NewsScheduler
5
+ from config import setup_logging, load_api_keys
6
 
7
+ # Logging-Konfiguration
8
  setup_logging()
9
 
10
+ async def main():
11
+ try:
12
+ scheduler = NewsScheduler()
13
+ await scheduler.start()
14
+ while True:
15
+ await asyncio.sleep(3600) # Hauptloop für kontinuierlichen Betrieb
16
+ except KeyboardInterrupt:
17
+ logging.info("Bot wurde ordnungsgemäß beendet")
18
+ except Exception as e:
19
+ logging.error(f"Kritischer Fehler: {str(e)}")
20
+ finally:
21
+ await scheduler.shutdown()
22
+
23
+ if __name__ == "__main__":
24
+ asyncio.run(main())