53 lines
2.8 KiB
Python
53 lines
2.8 KiB
Python
import requests
|
|
import json
|
|
|
|
base_url = "https://sibu-backend.onrender.com"
|
|
|
|
def login():
|
|
response = requests.post(f"{base_url}/api/auth/login", json={"email": "admin@sibu.com", "password": "admin"})
|
|
if response.status_code == 200:
|
|
return response.json().get("access_token")
|
|
else:
|
|
print("Login failed:", response.status_code, response.text)
|
|
return None
|
|
|
|
def create_route(token, route_data):
|
|
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
|
response = requests.post(f"{base_url}/api/routes", headers=headers, json=route_data)
|
|
if response.status_code == 200:
|
|
print(f"✅ Creada: {route_data['name']}")
|
|
else:
|
|
print(f"❌ Error en {route_data['name']}:", response.status_code, response.text)
|
|
|
|
def main():
|
|
print("Iniciando sesión...")
|
|
token = login()
|
|
if not token:
|
|
return
|
|
|
|
print("Inyectando rutas...")
|
|
routes = [
|
|
{"name": "Boquete - David", "origin_city": "Boquete", "destination_city": "David", "color": "#FEE715", "direction": "outbound", "distance_km": 38.0, "estimated_duration_minutes": 55, "average_speed_kmh": 40.0, "status": "active"},
|
|
{"name": "David - Boquete", "origin_city": "David", "destination_city": "Boquete", "color": "#FEE715", "direction": "inbound", "distance_km": 38.0, "estimated_duration_minutes": 55, "average_speed_kmh": 40.0, "status": "active"},
|
|
{"name": "Caldera - David", "origin_city": "Caldera", "destination_city": "David", "color": "#4CAF50", "direction": "outbound", "distance_km": 55.0, "estimated_duration_minutes": 75, "average_speed_kmh": 44.0, "status": "active"},
|
|
{"name": "David - Caldera", "origin_city": "David", "destination_city": "Caldera", "color": "#4CAF50", "direction": "inbound", "distance_km": 55.0, "estimated_duration_minutes": 75, "average_speed_kmh": 44.0, "status": "active"},
|
|
{"name": "Boquete - Caldera", "origin_city": "Boquete", "destination_city": "Caldera", "color": "#2196F3", "direction": "outbound", "distance_km": 22.0, "estimated_duration_minutes": 35, "average_speed_kmh": 38.0, "status": "active"},
|
|
{"name": "Caldera - Boquete", "origin_city": "Caldera", "destination_city": "Boquete", "color": "#2196F3", "direction": "inbound", "distance_km": 22.0, "estimated_duration_minutes": 35, "average_speed_kmh": 38.0, "status": "active"}
|
|
]
|
|
|
|
for route in routes:
|
|
create_route(token, route)
|
|
|
|
# Verificar rutas
|
|
print("\nVerificando rutas actuales en el servidor:")
|
|
r = requests.get(f"{base_url}/api/routes")
|
|
if r.status_code == 200:
|
|
current_routes = r.json()
|
|
print(f"Total rutas en el servidor: {len(current_routes)}")
|
|
if len(current_routes) > 0:
|
|
for rt in current_routes:
|
|
print(f" - {rt['name']}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|