Spaces:
Sleeping
Sleeping
File size: 2,423 Bytes
40b32ad c7a9eee 2b296dd aa2bb36 2b296dd c775bf3 2b296dd 40b32ad c7a9eee aa2bb36 40b32ad b570086 aa2bb36 73869d0 e68f733 bca36b9 73869d0 152f6de 40b32ad 152f6de d658933 40b32ad d658933 73869d0 e68f733 aa2bb36 e68f733 aa2bb36 e68f733 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import os
from fastapi import FastAPI, Query, Response
import requests
import json
app = FastAPI()
# Leer las variables secretas
url_base = os.getenv("URL_BASE")
second_url_base = os.getenv("SECOND_URL_BASE")
third_url_base = os.getenv("THIRD_URL_BASE")
@app.get("/eatc-headers")
async def get_eatc_headers(eatc_code: str = Query(..., description="EATC code to retrieve headers for")):
url = f"{url_base}/api/abaco/eatc_dona_headers?eatc-code={eatc_code}"
response = requests.get(url)
if response.status_code == 200:
response_json = json.loads(response.text)
if len(response_json) >= 2 and "res" in response_json and response_json["res"]:
eatc_code_value = response_json["res"][0]["eatc-code"]
eatc_match_asignation_rule_value = response_json["res"][0].get("eatc_match_asignation_rule", "")
eatc_state_value = response_json["res"][0].get("eatc-state", "")
eatc_extended_value = response_json["res"][0].get("eatc_extended", "")
eatc_pod_id_value = response_json["res"][0].get("eatc-pod_id", "")
# Realizar la segunda consulta
second_url = f"{second_url_base}/api/eatcloud/eatc_direct_dona?eatc_pod_id={eatc_pod_id_value}"
second_response = requests.get(second_url)
eatc_asignacion_directa = "SI" if second_response.status_code == 200 else "NO"
# Realizar la tercera consulta
third_url = f"{third_url_base}/api/abaco/eatc_match_registry?eatc-dona_header_code={eatc_code_value}"
third_response = requests.get(third_url)
third_response_json = json.loads(third_response.text)
eatc_match_cantidad = len(third_response_json)
report = f"eatc_code: {eatc_code_value}\n\neatc_match_asignation_rule: {eatc_match_asignation_rule_value}\n\neatc_state: {eatc_state_value}\n\neatc_extended: {eatc_extended_value}\n\neatc_pod_id: {eatc_pod_id_value}\n\neatc_asignacion_directa: {eatc_asignacion_directa}\n\neatc_match_cantidad: {eatc_match_cantidad}\n\n"
return Response(content=report, media_type="text/plain")
else:
return Response(content="Error: Invalid response from API", media_type="text/plain", status_code=400)
else:
return Response(content="Error: API returned error status code", media_type="text/plain", status_code=400) |