Spaces:
Sleeping
Sleeping
mobixconsulting
commited on
Commit
•
b570086
1
Parent(s):
d23ef2a
Update main.py
Browse files
main.py
CHANGED
@@ -1,43 +1,10 @@
|
|
1 |
-
from fastapi import FastAPI,
|
2 |
import requests
|
3 |
-
import pandas as pd
|
4 |
-
from io import StringIO
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
-
@app.get("/")
|
9 |
-
async def
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
async def consulta_data(fecha_inicio_value: str = Query(...), fecha_fin_value: str = Query(...), cod_donacion: str = Query(...)):
|
14 |
-
try:
|
15 |
-
# Realizar la solicitud para obtener datos de match
|
16 |
-
match_url = "https://beneficiarios.eatcloud.info/api/abaco/eatc_match_registry?eatc-dona_header_code=_*&_csv"
|
17 |
-
match_response = requests.get(match_url)
|
18 |
-
match_data = match_response.json()["csv"]
|
19 |
-
df_match = pd.read_csv(StringIO(requests.get(match_data).content.decode('latin-1')), delimiter=';')
|
20 |
-
|
21 |
-
# Realizar la solicitud para obtener datos de donación
|
22 |
-
donation_url = f"https://donantes.eatcloud.info/api/abaco/eatc_dona_headers?eatc-publication_date[0]={fecha_inicio_value}&eatc-publication_date[1]={fecha_fin_value}&_csv"
|
23 |
-
donation_response = requests.get(donation_url)
|
24 |
-
donation_data = donation_response.json()["csv"]
|
25 |
-
df_headers = pd.read_csv(StringIO(requests.get(donation_data).content.decode('latin-1')), delimiter=';')
|
26 |
-
|
27 |
-
# Filtrar registros por código de donación
|
28 |
-
filtered_df = df_match[df_match['eatc-dona_header_code'] == cod_donacion]
|
29 |
-
|
30 |
-
if not filtered_df.empty:
|
31 |
-
pod_name_y_dona_header_code = filtered_df[['eatc-pod_name', 'eatc-dona_header_code']]
|
32 |
-
message = f"Para 'eatc-dona_header_code' igual a '{cod_donacion}', hay {len(filtered_df)} registros en el MATCH."
|
33 |
-
else:
|
34 |
-
message = f"La donación ingresada 'eatc-dona_header' igual a '{cod_donacion}' no tiene registros en el MATCH."
|
35 |
-
|
36 |
-
return {"message": message}
|
37 |
-
|
38 |
-
except Exception as e:
|
39 |
-
raise HTTPException(status_code=500, detail=str(e))
|
40 |
-
|
41 |
-
if __name__ == "__main__":
|
42 |
-
import uvicorn
|
43 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
import requests
|
|
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
@app.get("/eatc-headers/{eatc_code}")
|
7 |
+
async def get_eatc_headers(eatc_code: str):
|
8 |
+
url = f"https://donantes.eatcloud.info/api/abaco/eatc_dona_headers?eatc-code={eatc_code}"
|
9 |
+
response = requests.get(url)
|
10 |
+
return response.json()[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|