from playwright.sync_api import sync_playwright import json import time from datetime import datetime class RealtimeJSONInterceptor: def init(self): self.collected_data = {} self.output_file = "fmp_data.json" # Simple file name def handle_response(self, response): """Network Response တိုင်းကို ကြားဖြတ်ဖမ်းယူမည့် Function""" try: # Content-Type က JSON ဟုတ်/မဟုတ် စစ်ဆေးခြင်း content_type = response.headers.get('content-type', '') if 'json' not in content_type.lower(): return # URL က api.fmp.live/query ဟုတ်/မဟုတ် စစ်ဆေးခြင်း if 'api.fmp.live/query' not in response.url: return # Response ကို JSON အဖြစ် ဖတ်ခြင်း data = response.json() # Data ထဲမှာ "data" key ပါ/မပါ စစ်ဆေးခြင်း if 'data' not in data: return # Data ထဲက key တွေကို ကျွန်တော်တို့ dictionary ထဲ ထည့်ခြင်း for key, value in data['data'].items(): # အရင် data နဲ့ တူ/မတူ စစ်ဆေးခြင်း (Update ဖြစ်မှသာ ပြမယ်) if key not in self.collected_data or self.collected_data[key] != value: self.collected_data[key] = value # Console မှာ Live Update ပြသခြင်း timestamp = datetime.now().strftime("%H:%M:%S") print(f"[{timestamp}] ✅ {key} - {self._get_summary(value)}") # JSON file ကို အမြဲ update လုပ်ခြင်း self.save_to_file() except Exception as e: pass def _get_summary(self, value): """Data အကျဉ်းချုပ်ကို ပြသရန်""" if isinstance(value, list): return f"{len(value)} items" elif isinstance(value, dict): return f"{len(value)} keys" else: return str(value)[:30] def save_to_file(self): """Collected data ကို JSON file အဖြစ် save လုပ်မည်""" try: with open(self.output_file, 'w', encoding='utf-8') as f: json.dump(self.collected_data, f, indent=2, ensure_ascii=False) except Exception as e: print(f"❌ File save error: {e}") def run(self): """Main function - Browser ကို ဖွင့်ပြီး monitoring စတင်မည်""" print("="*60) print("🚀 FMP Live Real-time JSON Interceptor") print("="*60) print(f"📁 Data ကို '{self.output_file}' တွင် save လုပ်နေပါမည်") print("⏹️ ရပ်ရန် Ctrl+C ကို နှိပ်ပါ\n") with sync_playwright() as p: browser = p.chromium.launch(headless=False) page = browser.new_page() page.on("response", self.handle_response) print("🌐 fmp.live သို့ ချိတ်ဆက်နေပါသည်...") try: page.goto("https://fmp.live/", wait_until="networkidle") print("✅ Website load ဖြစ်ပါပြီ") print("👀 Real-time monitoring စတင်ပါပြီ...\n") while True: time.sleep(1) except KeyboardInterrupt: print("\n\n⏹️ User မှ ရပ်ဆိုင်းလိုက်ပါသည်") except Exception as e: print(f"\n❌ Error: {e}") finally: self.save_to_file() print(f"\n✅ နောက်ဆုံး data ကို '{self.output_file}' တွင် သိမ်းဆည်းပြီးပါပြီ") browser.close() if name == "main": interceptor = RealtimeJSONInterceptor() interceptor.run()