|
|
import tempfile |
|
|
import os |
|
|
import time |
|
|
import socket |
|
|
|
|
|
def obtenAccesoHF(): |
|
|
if local_check(): |
|
|
print("Estoy en entorno Local...") |
|
|
import bridges |
|
|
llave = bridges.llave |
|
|
else: |
|
|
print("Estoy en entorno Remoto...") |
|
|
llave = os.getenv("llave") |
|
|
print("Ésto es llave:", llave) |
|
|
|
|
|
return llave |
|
|
|
|
|
def local_check(): |
|
|
|
|
|
hostname = socket.gethostname() |
|
|
|
|
|
print("Dentro de local_check... , el hostname es: ", hostname) |
|
|
time.sleep(2) |
|
|
|
|
|
|
|
|
if hostname: |
|
|
print("Ejecutando api en el servidor.") |
|
|
return False |
|
|
else: |
|
|
print("Ejecutando api en local.") |
|
|
return True |
|
|
|
|
|
async def imageToTemp(image): |
|
|
|
|
|
print("Estoy en imageToTemp...") |
|
|
|
|
|
try: |
|
|
with tempfile.NamedTemporaryFile(delete=False, suffix=f"_{image.filename}") as tmp_file: |
|
|
contents = await image.read() |
|
|
tmp_file.write(contents) |
|
|
temp_file_path = tmp_file.name |
|
|
|
|
|
print(f"Archivo temporal guardado en: {temp_file_path}") |
|
|
return temp_file_path |
|
|
|
|
|
except Exception as e: |
|
|
print(f"Error al procesar el archivo: {e}") |
|
|
return {"error": "Error al procesar la imagen"} |
|
|
|
|
|
|
|
|
def borraTemp(archivo): |
|
|
try: |
|
|
os.remove(archivo) |
|
|
print(f"Archivo temporal eliminado: {archivo}") |
|
|
return True |
|
|
except FileNotFoundError: |
|
|
print(f"Advertencia: Archivo no encontrado para eliminar: {archivo}") |
|
|
except Exception as e: |
|
|
print(f"Error al eliminar el archivo {archivo}: {e}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|