import urllib.request import json import urllib.error def fetch_data(): try: req = urllib.request.Request( 'http://92.38.48.166:8080/proxy/auth/auth/login', data=json.dumps({"username": "admin", "password": "admin123"}).encode('utf-8'), headers={'Content-Type': 'application/json'} ) login_resp = urllib.request.urlopen(req) token = json.loads(login_resp.read().decode()).get('access_token') headers = {'Authorization': f'Bearer {token}'} calls_req = urllib.request.Request( 'http://92.38.48.166:8080/proxy/asterisk-bridge/asterisk/events?limit=25', headers=headers ) calls_resp = urllib.request.urlopen(calls_req) events = json.loads(calls_resp.read().decode()) if not events: print("No events found.") return for call_id in ["1775500989.2", "1775499861.0"]: ai_req = urllib.request.Request( f'http://92.38.48.166:8080/proxy/asterisk-bridge/asterisk/live-calls/{call_id}/ai-summary', headers=headers ) try: ai_resp = urllib.request.urlopen(ai_req) ai_data = json.loads(ai_resp.read().decode()) print(f"\n----- AI SUMMARY FOR {call_id} -----") with open(f"e:\\Zhan\\summary_{call_id}.json", "w", encoding="utf-8") as f: json.dump(ai_data, f, ensure_ascii=False, indent=2) print(f"Saved to e:\\Zhan\\summary_{call_id}.json") except urllib.error.HTTPError as e: print(f"Call {call_id} error: {e}") except Exception as e: print(f"Error: {e}") if __name__ == '__main__': fetch_data()