#!/usr/bin/env python3 """ Genera comandos curl con autenticación real para endpoints funcionales """ from adif_auth import AdifAuthenticator import json import uuid ACCESS_KEY = "and20210615" SECRET_KEY = "Jthjtr946RTt" def generate_curl(endpoint_name, url, payload, user_key): """ Genera un comando curl completo con headers de autenticación """ auth = AdifAuthenticator(access_key=ACCESS_KEY, secret_key=SECRET_KEY) user_id = str(uuid.uuid4()) headers = auth.get_auth_headers("POST", url, payload, user_id=user_id) headers["User-key"] = user_key print(f"\n{'='*70}") print(f"{endpoint_name}") print(f"{'='*70}\n") curl_cmd = f'curl -X POST "{url}" \\\n' for key, value in headers.items(): curl_cmd += f' -H "{key}: {value}" \\\n' payload_json = json.dumps(payload, separators=(',', ':')) curl_cmd += f" -d '{payload_json}'" print(curl_cmd) print() # 1. SALIDAS (Departures) - Madrid Atocha generate_curl( "SALIDAS desde Madrid Atocha", "https://circulacion.api.adif.es/portroyalmanager/secure/circulationpaths/departures/traffictype/", { "commercialService": "BOTH", "commercialStopType": "BOTH", "page": {"pageNumber": 0}, "stationCode": "10200", "trafficType": "ALL" }, "f4ce9fbfa9d721e39b8984805901b5df" ) # 2. LLEGADAS (Arrivals) - Madrid Atocha generate_curl( "LLEGADAS a Madrid Atocha", "https://circulacion.api.adif.es/portroyalmanager/secure/circulationpaths/arrivals/traffictype/", { "commercialService": "BOTH", "commercialStopType": "BOTH", "page": {"pageNumber": 0}, "stationCode": "10200", "trafficType": "ALL" }, "f4ce9fbfa9d721e39b8984805901b5df" ) # 3. SALIDAS - Barcelona Sants generate_curl( "SALIDAS desde Barcelona Sants", "https://circulacion.api.adif.es/portroyalmanager/secure/circulationpaths/departures/traffictype/", { "commercialService": "BOTH", "commercialStopType": "BOTH", "page": {"pageNumber": 0}, "stationCode": "71801", "trafficType": "ALL" }, "f4ce9fbfa9d721e39b8984805901b5df" ) # 4. OBSERVACIONES de estaciones generate_curl( "OBSERVACIONES de estaciones", "https://estaciones.api.adif.es/portroyalmanager/secure/stationsobservations/", { "stationCodes": ["10200", "71801"] }, "0d021447a2fd2ac64553674d5a0c1a6f" ) print("\n" + "="*70) print("NOTA: Estos curls son válidos por ~5 minutos (timestamp dinámico)") print("Para obtener nuevos curls, ejecuta: python3 generate_curl.py") print("="*70)