fastapi / main.py
mobixconsulting's picture
Update main.py
4c40977 verified
raw
history blame
1.1 kB
from fastapi import FastAPI, Query
from pydantic import BaseModel
import requests
import json
import pandas as pd
app = FastAPI()
class EatcHeadersResponse(BaseModel):
report: str
@app.get("/eatc-headers", response_model=EatcHeadersResponse)
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"]:
data = {
"eatc_code": response_json["res"][0]["eatc-code"],
"eatc_match_asignation_rule": response_json["res"][0].get("eatc_match_asignation_rule", "")
}
df = pd.DataFrame([data])
return {"report": df.to_string(index=False)}
else:
return {"error": "Invalid response from API"}
else:
return {"error": "API returned error status code"}