Taragonis commited on
Commit
cc8e163
·
verified ·
1 Parent(s): bd5fad3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -4,6 +4,8 @@ import json
4
  import re
5
  import requests
6
  import gradio as gr
 
 
7
  from groq import Groq
8
  from serpapi import GoogleSearch
9
 
@@ -22,22 +24,25 @@ client = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None
22
  # Utilities (SERPAPI + Notion)
23
  # -------------------------
24
 
25
- # --- Función auxiliar para fecha ---
26
  def extraer_fecha(texto):
27
  match = re.search(r"hace (\d+) (día|días|semana|semanas|mes|meses)", texto, re.IGNORECASE)
28
  if not match:
29
  return None
 
30
  num = int(match.group(1))
31
  unidad = match.group(2).lower()
32
  hoy = datetime.now()
33
 
 
34
  if "semana" in unidad:
35
- delta = timedelta(weeks=num)
36
  elif "mes" in unidad:
37
- delta = timedelta(days=num * 30)
38
  else:
39
- delta = timedelta(days=num)
40
- return (hoy - delta).strftime("%Y-%m-%d")
 
41
 
42
 
43
  def buscar_url_empresa(nombre_empresa, logs):
@@ -116,7 +121,7 @@ def buscar_puntaje_glassdoor(nombre_empresa, logs):
116
  ])
117
  m = re.search(r"([0-5](?:[.,]\d)?)\s*(?:de|out of)?\s*5", blob, flags=re.I)
118
  if m:
119
- val = m.group(1).replace(",", ".")
120
  try:
121
  rating = float(val)
122
  logs.append(f"🌟 Puntaje (regex) detectado: {rating}")
@@ -143,8 +148,8 @@ def subir_a_notion(data, logs):
143
  "Notion-Version": "2022-06-28"
144
  }
145
 
146
- rating_original = data.get("Ptos Glassdoor")
147
- rating_100 = int(rating_original * 20) if isinstance(rating_original, (int, float)) else None
148
 
149
  props = {
150
  "Empresa": {"title": [{"text": {"content": data.get("Empresa", "Sin nombre")}}]},
@@ -156,7 +161,7 @@ def subir_a_notion(data, logs):
156
  "date": {"start": str(data.get("Fecha Publicación"))}
157
  } if data.get("Fecha Publicación") else None,
158
  "URL Empresa": {"url": data.get("URL Empresa")},
159
- "Ptos Glassdoor": {"number": rating_100}
160
  }
161
 
162
  payload = {"parent": {"database_id": NOTION_DATABASE_ID}, "properties": props}
@@ -270,7 +275,7 @@ def process_job(texto, send_to_notion):
270
  data = call_model(texto, logs) or {}
271
  empresa = data.get("Empresa")
272
 
273
- # --- Corrección de fecha ---
274
  if "Fecha Publicación" in data and data["Fecha Publicación"]:
275
  fecha_convertida = extraer_fecha(data["Fecha Publicación"])
276
  if fecha_convertida:
@@ -279,10 +284,7 @@ def process_job(texto, send_to_notion):
279
  else:
280
  logs.append("⚠️ No pude convertir la fecha, dejo valor original.")
281
 
282
-
283
- # -------------------------------------------------
284
- # CORRECCIÓN: solo usamos "URL Empresa"
285
- # -------------------------------------------------
286
  url = data.get("URL Empresa")
287
  if not url:
288
  nueva = buscar_url_empresa(empresa, logs)
 
4
  import re
5
  import requests
6
  import gradio as gr
7
+ from datetime import datetime, timedelta
8
+ from dateutil.relativedelta import relativedelta
9
  from groq import Groq
10
  from serpapi import GoogleSearch
11
 
 
24
  # Utilities (SERPAPI + Notion)
25
  # -------------------------
26
 
27
+ # --- FIX FECHA: usar relativedelta para año correcto ---
28
  def extraer_fecha(texto):
29
  match = re.search(r"hace (\d+) (día|días|semana|semanas|mes|meses)", texto, re.IGNORECASE)
30
  if not match:
31
  return None
32
+
33
  num = int(match.group(1))
34
  unidad = match.group(2).lower()
35
  hoy = datetime.now()
36
 
37
+ # FIX → mes correcto, sin restar "30 días"
38
  if "semana" in unidad:
39
+ fecha = hoy - relativedelta(weeks=num)
40
  elif "mes" in unidad:
41
+ fecha = hoy - relativedelta(months=num)
42
  else:
43
+ fecha = hoy - relativedelta(days=num)
44
+
45
+ return fecha.strftime("%Y-%m-%d")
46
 
47
 
48
  def buscar_url_empresa(nombre_empresa, logs):
 
121
  ])
122
  m = re.search(r"([0-5](?:[.,]\d)?)\s*(?:de|out of)?\s*5", blob, flags=re.I)
123
  if m:
124
+ val = m.group(1).replace(",", "")
125
  try:
126
  rating = float(val)
127
  logs.append(f"🌟 Puntaje (regex) detectado: {rating}")
 
148
  "Notion-Version": "2022-06-28"
149
  }
150
 
151
+ #rating_original = data.get("Ptos Glassdoor")
152
+ #rating_100 = int(rating_original * 20) if isinstance(rating_original, (int, float)) else None
153
 
154
  props = {
155
  "Empresa": {"title": [{"text": {"content": data.get("Empresa", "Sin nombre")}}]},
 
161
  "date": {"start": str(data.get("Fecha Publicación"))}
162
  } if data.get("Fecha Publicación") else None,
163
  "URL Empresa": {"url": data.get("URL Empresa")},
164
+ "Ptos Glassdoor": {"number": rating}
165
  }
166
 
167
  payload = {"parent": {"database_id": NOTION_DATABASE_ID}, "properties": props}
 
275
  data = call_model(texto, logs) or {}
276
  empresa = data.get("Empresa")
277
 
278
+ # --- Fecha corregida ---
279
  if "Fecha Publicación" in data and data["Fecha Publicación"]:
280
  fecha_convertida = extraer_fecha(data["Fecha Publicación"])
281
  if fecha_convertida:
 
284
  else:
285
  logs.append("⚠️ No pude convertir la fecha, dejo valor original.")
286
 
287
+ # URL Empresa
 
 
 
288
  url = data.get("URL Empresa")
289
  if not url:
290
  nueva = buscar_url_empresa(empresa, logs)