Spaces:
No application file
No application file
Update calendario api
Browse files- calendario api +42 -1
calendario api
CHANGED
|
@@ -147,4 +147,45 @@ def adaptar_a_formato_oracle(item):
|
|
| 147 |
@app.post("/adaptar_a_oracle")
|
| 148 |
async def adaptar_a_oracle(json_original: List[dict]):
|
| 149 |
json_adaptado = [adaptar_a_formato_oracle(item) for item in json_original]
|
| 150 |
-
return json_adaptado
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
@app.post("/adaptar_a_oracle")
|
| 148 |
async def adaptar_a_oracle(json_original: List[dict]):
|
| 149 |
json_adaptado = [adaptar_a_formato_oracle(item) for item in json_original]
|
| 150 |
+
return json_adaptado
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
from fastapi import FastAPI, File, UploadFile
|
| 156 |
+
from fastapi.responses import FileResponse
|
| 157 |
+
import pandas as pd
|
| 158 |
+
import io
|
| 159 |
+
from typing import List
|
| 160 |
+
|
| 161 |
+
app = FastAPI()
|
| 162 |
+
|
| 163 |
+
def adaptar_a_formato_oracle(item):
|
| 164 |
+
nuevo_item = {"resourceId": item["resourceId"], "workSchedules": []}
|
| 165 |
+
|
| 166 |
+
for fecha, status in item.items():
|
| 167 |
+
if fecha != "resourceId":
|
| 168 |
+
record_type = "Descanso Semanal" if status == "Descanso Semanal" else "Ok"
|
| 169 |
+
nuevo_item["workSchedules"].append({
|
| 170 |
+
"recordType": record_type,
|
| 171 |
+
"startDate": fecha,
|
| 172 |
+
"endDate": fecha # Puedes ajustar esto seg煤n tu l贸gica
|
| 173 |
+
})
|
| 174 |
+
|
| 175 |
+
return nuevo_item
|
| 176 |
+
|
| 177 |
+
@app.post("/excel_json/")
|
| 178 |
+
async def excel_json(file: UploadFile = File(...), sheet_name: str = "Nombre_hoja"):
|
| 179 |
+
df = pd.read_excel(io.BytesIO(await file.read()), engine='openpyxl', sheet_name=sheet_name)
|
| 180 |
+
|
| 181 |
+
# Transformar el formato al deseado para Oracle
|
| 182 |
+
json_original = df.to_dict(orient="records")
|
| 183 |
+
json_adaptado = [adaptar_a_formato_oracle(item) for item in json_original]
|
| 184 |
+
|
| 185 |
+
# Guardar el JSON adaptado en un archivo
|
| 186 |
+
json_file = "output.json"
|
| 187 |
+
with open(json_file, "w") as output_file:
|
| 188 |
+
output_file.write(str(json_adaptado))
|
| 189 |
+
|
| 190 |
+
# Devolver el archivo JSON adaptado como respuesta
|
| 191 |
+
return FileResponse(json_file, media_type='application/json', filename=json_file)
|