File size: 1,249 Bytes
aa2bb36
 
2b296dd
aa2bb36
2b296dd
c775bf3
2b296dd
aa2bb36
 
c50d0da
5659f36
aa2bb36
b570086
 
aa2bb36
 
 
73869d0
 
 
5659f36
73869d0
5659f36
aa2bb36
5659f36
aa2bb36
5659f36
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
from fastapi import FastAPI, Query
from pydantic import BaseModel
import requests
import json

app = FastAPI()

class EatcHeadersResponse(BaseModel):
    report: str

@app.get("/eatc-headers", response_class=HTMLResponse)
async def get_eatc_headers(eatc_code: str = Query(..., description="EATC code to retrieve headers for")):
    url = f"https://donantes.eatcloud.info/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", "")
            
            report = f"<p>eatc_code: {eatc_code_value}</p><p>eatc_match_asignation_rule: {eatc_match_asignation_rule_value}</p>"
            
            return HTMLResponse(content=report, status_code=200)
        else:
            return HTMLResponse(content="<p>Error: Invalid response from API</p>", status_code=400)
    else:
        return HTMLResponse(content="<p>Error: API returned error status code</p>", status_code=400)