latapp 10 месяцев назад
Родитель
Сommit
4ba3de4500
2 измененных файлов с 24 добавлено и 6 удалено
  1. 24 0
      fudo/fudo.py
  2. 0 6
      main.py

+ 24 - 0
fudo/fudo.py

@@ -1,16 +1,40 @@
 import math
+from time import time
 import requests
 import os
 api_token = os.getenv('FUDO_API_KEY')
 api_secret = os.getenv('FUDO_API_SECRET')
 
 def get_token():
+    """
+    revisa el archivo dksdabjhvjhSADhsbjksf.txt para ver si el token ya fue guardado,
+    este contiene 3 lineas
+    la primera es el token, la segunda es la fecha de expiracion del token. y la tercera es la fecha de creacion del token.
+    si el token no existe o ya expiro, se genera uno nuevo y se guarda en el archivo.
+    si el token existe y no ha expirado, se devuelve el token.
+    """
+
+    # if os.path.exists("dksdabjhvjhSADhsbjksf.txt"):
+    #     with open("dksdabjhvjhSADhsbjksf.txt", "r") as f:
+    #         lines = f.readlines()
+    #         if len(lines) == 3:
+    #             token = lines[0].strip()
+    #             expiration = lines[1].strip()
+    #             created = lines[2].strip()
+    #             if expiration - (time.time() - int(created)) < 0:
+    #                 return token
     url = 'https://auth.fu.do/api'
     data = {
         "apiKey": api_token,
         "apiSecret": api_secret
     }
+    
     r = requests.post(url, data=data)
+    with open("dksdabjhvjhSADhsbjksf.txt", "w") as f:
+        f.write(r.json()['token'] + "\n")
+        f.write(str(r.json()['expiration']) + "\n")
+        f.write(str(time.time()) + "\n")
+    print(r.json())
     return r.json()['token']
     
 def get_categorys():

+ 0 - 6
main.py

@@ -21,8 +21,6 @@ from email.message import EmailMessage
 load_dotenv()
 import fudo.fudo as fd
 
-
-
 # Configuration
 OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
 PORT = int(os.getenv("PORT", 6001))
@@ -39,7 +37,6 @@ if not OPENAI_API_KEY:
     # Potentially exit or prevent app startup if critical env var is missing
     # raise ValueError("OPENAI_API_KEY is not set, cannot start application.")
 
-
 # --- FastAPI App Initialization ---
 app = FastAPI(title="Web Pedidos Klein - FastAPI Backend")
 
@@ -142,7 +139,6 @@ def send_email():
         smtp.login(EMAIL_ORIGEN, CONTRASENA)
         smtp.send_message(msg)
 
-
 def load_bg_data() -> List[Dict[str, str]]:
     try:
         with open(BG_DATA_PATH, 'r', encoding='utf-8') as f:
@@ -332,7 +328,6 @@ async def printer_order(order: OrderWeb):
             writer = csv.writer(f)
             writer.writerow([order.customerName, order.table, order.orderDate, list(map(lambda item: item.name, items))])
 
-
 @app.post("/api/chat/completions",
           summary="Get chat completions from OpenAI",
           dependencies=[Depends(protect_chat_api)])
@@ -355,7 +350,6 @@ async def chat_completions(request_data: ChatCompletionRequest, request: Request
         print(f"Unexpected error in /api/chat/completions: {e}")
         raise HTTPException(status_code=500, detail="Error interno del servidor al procesar el chat.")
 
-
 @app.get("/", response_class=HTMLResponse, include_in_schema=False)
 async def serve_index_html():
     index_path = os.path.join("public", "index.html")