Álvaro Valenzuela Valdes
feat: enhance AI agents with detailed Mercado Publico data and update frontend UI
0d71eae | import httpx | |
| import asyncio | |
| import json | |
| async def test_full_api(): | |
| ticket = "99B4CA8C-C1DF-4E3F-B5CF-C1672D432A91" | |
| # 1. Fetch active tenders | |
| url_active = f"https://api.mercadopublico.cl/servicios/v1/publico/licitaciones.json?estado=activas&ticket={ticket}" | |
| print(f"Fetching active tenders: {url_active}") | |
| async with httpx.AsyncClient(timeout=30) as client: | |
| try: | |
| resp = await client.get(url_active) | |
| data = resp.json() | |
| items = data.get("Listado", []) | |
| print(f"Found {len(items)} active items.") | |
| if items: | |
| code = items[0].get("CodigoExterno") | |
| print(f"Fetching details for code: {code}") | |
| url_detail = f"https://api.mercadopublico.cl/servicios/v1/publico/licitaciones.json?codigo={code}&ticket={ticket}" | |
| resp_detail = await client.get(url_detail) | |
| detail_data = resp_detail.json() | |
| print("Detail sample:") | |
| print(json.dumps(detail_data, indent=2)) | |
| # Save to file for reference | |
| with open("api_sample_detail.json", "w") as f: | |
| json.dump(detail_data, f, indent=2) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| if __name__ == "__main__": | |
| asyncio.run(test_full_api()) | |