kaan1233/bistelligence-api
0
1import json2import re3 4with open('server.py', 'r', encoding='utf-8') as f:5 content = f.read()6 7cache_logic = """ global market_regime, stock_data, recommendations, elite_ai_report8 cache_file = "ai_cache.json"9 import time10 11 # Cache Kontrolü (6 saatten yeniyse kullan)12 if os.path.exists(cache_file):13 file_age = time.time() - os.path.getmtime(cache_file)14 if file_age < 6 * 3600:15 print("[ÖNBELLEK] Son 6 saat içinde analiz yapılmış. Cache yükleniyor...")16 try:17 with open(cache_file, "r", encoding="utf-8") as f:18 cache_data = json.load(f)19 market_regime = cache_data.get("market_regime", {})20 stock_data = cache_data.get("stock_data", {})21 recommendations = cache_data.get("recommendations", [])22 elite_ai_report = cache_data.get("elite_ai_report", "Önbellekten yüklendi.")23 print(f" {len(recommendations)} hisse sonucu önbellekten alındı. (API KOTASI KORUNDU)")24 return25 except Exception as e:26 print(f"[UYARI] Önbellek okunamadı: {e}. Yeniden analiz edilecek.")27"""28 29content = content.replace(" global market_regime, stock_data, recommendations\n", cache_logic)30 31save_cache_logic = """32 print(f"{'=' * 60}")33 34 # Önbelleğe Kaydet35 try:36 cache_data = {37 "market_regime": market_regime,38 "stock_data": stock_data,39 "recommendations": recommendations,40 "elite_ai_report": elite_ai_report41 }42 with open("ai_cache.json", "w", encoding="utf-8") as f:43 json.dump(cache_data, f, ensure_ascii=False)44 print(" Sonuçlar başarıyla ai_cache.json dosyasına kaydedildi.")45 except Exception as e:46 print(f" Cache kaydedilemedi: {e}")47"""48 49content = content.replace(" print(f\"{'=' * 60}\")\n\n@app.on_event(\"startup\")", save_cache_logic + "\n@app.on_event(\"startup\")")50 51with open('server.py', 'w', encoding='utf-8') as f:52 f.write(content)53 