tx3bas commited on
Commit
b42bcaf
·
verified ·
1 Parent(s): 5e74413

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -10,6 +10,25 @@ import unicodedata
10
  def normalize_keyword(keyword):
11
  return ''.join(c for c in unicodedata.normalize('NFD', keyword.lower()) if unicodedata.category(c) != 'Mn')
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # Función para obtener sugerencias de Qwant
14
  def fetch_qwant_suggestions(query, lang_code="es"):
15
  encoded_query = urllib.parse.quote(query)
@@ -156,6 +175,7 @@ def main(keyword):
156
  bing_suggestions_all = []
157
  amazon_suggestions_all = []
158
  qwant_suggestions_all = [] # Para almacenar las sugerencias de Qwant
 
159
 
160
  # Obtener sugerencias de DuckDuckGo
161
  for exp_keyword in expanded_keywords:
@@ -201,6 +221,13 @@ def main(keyword):
201
  for suggestion in suggestions:
202
  all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
203
 
 
 
 
 
 
 
 
204
  # Obtener las top 10 sugerencias de cada plataforma
205
  google_top_10 = get_top_suggestions(google_suggestions_all, top_n=10)
206
  duckduckgo_top_10 = get_top_suggestions(duckduckgo_suggestions_all, top_n=10)
@@ -208,6 +235,7 @@ def main(keyword):
208
  bing_top_10 = get_top_suggestions(bing_suggestions_all, top_n=10)
209
  amazon_top_10 = get_top_suggestions(amazon_suggestions_all, top_n=10)
210
  qwant_top_10 = get_top_suggestions(qwant_suggestions_all, top_n=10)
 
211
 
212
  # Ordenar las sugerencias combinadas por frecuencia
213
  combined_top_10_suggestions = get_top_suggestions(all_suggestions, top_n=10)
@@ -222,7 +250,7 @@ def main(keyword):
222
  # Crear el HTML de salida con un botón de copia
223
  html_output = f"""
224
  <div>
225
- <b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing, Amazon y Qwant (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
226
  <button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
227
  onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'>&nbsp;✂&nbsp;</button>
228
  </div>
@@ -246,6 +274,9 @@ def main(keyword):
246
  html_output += "</ul><h4>Top 10 Sugerencias de Qwant:</h4><ul>"
247
  for suggestion, freq in qwant_top_10:
248
  html_output += f"<li>{suggestion} ({freq})</li>"
 
 
 
249
  html_output += "</ul>"
250
 
251
  return html_output
 
10
  def normalize_keyword(keyword):
11
  return ''.join(c for c in unicodedata.normalize('NFD', keyword.lower()) if unicodedata.category(c) != 'Mn')
12
 
13
+ # Función para obtener sugerencias de Brave
14
+ def fetch_brave_suggestions(query, lang_code="es"):
15
+ encoded_query = urllib.parse.quote(query)
16
+ url = f"https://search.brave.com/api/suggest?q={encoded_query}"
17
+ response = requests.get(url)
18
+ if response.status_code == 200:
19
+ try:
20
+ data = response.json()
21
+ if len(data) > 1 and isinstance(data[1], list):
22
+ return [normalize_keyword(item) for item in data[1]]
23
+ else:
24
+ print("No se encontraron sugerencias en el formato esperado (Brave).")
25
+ return []
26
+ except ValueError:
27
+ print("Error decodificando JSON de Brave")
28
+ return []
29
+ else:
30
+ return []
31
+
32
  # Función para obtener sugerencias de Qwant
33
  def fetch_qwant_suggestions(query, lang_code="es"):
34
  encoded_query = urllib.parse.quote(query)
 
175
  bing_suggestions_all = []
176
  amazon_suggestions_all = []
177
  qwant_suggestions_all = [] # Para almacenar las sugerencias de Qwant
178
+ brave_suggestions_all = [] # Para almacenar las sugerencias de Brave
179
 
180
  # Obtener sugerencias de DuckDuckGo
181
  for exp_keyword in expanded_keywords:
 
221
  for suggestion in suggestions:
222
  all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
223
 
224
+ # Obtener sugerencias de Brave
225
+ for exp_keyword in expanded_keywords:
226
+ suggestions = fetch_brave_suggestions(exp_keyword)
227
+ brave_suggestions_all.extend(suggestions)
228
+ for suggestion in suggestions:
229
+ all_suggestions[suggestion] = all_suggestions.get(suggestion, 0) + 1
230
+
231
  # Obtener las top 10 sugerencias de cada plataforma
232
  google_top_10 = get_top_suggestions(google_suggestions_all, top_n=10)
233
  duckduckgo_top_10 = get_top_suggestions(duckduckgo_suggestions_all, top_n=10)
 
235
  bing_top_10 = get_top_suggestions(bing_suggestions_all, top_n=10)
236
  amazon_top_10 = get_top_suggestions(amazon_suggestions_all, top_n=10)
237
  qwant_top_10 = get_top_suggestions(qwant_suggestions_all, top_n=10)
238
+ brave_top_10 = get_top_suggestions(brave_suggestions_all, top_n=10)
239
 
240
  # Ordenar las sugerencias combinadas por frecuencia
241
  combined_top_10_suggestions = get_top_suggestions(all_suggestions, top_n=10)
 
250
  # Crear el HTML de salida con un botón de copia
251
  html_output = f"""
252
  <div>
253
+ <b>Sugerencias combinadas de Google, DuckDuckGo, YouTube, Bing, Amazon, Qwant y Brave (Top 10 combinadas):</b> <span id='suggestions_text'>{suggestions_str}</span>
254
  <button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;"
255
  onclick='navigator.clipboard.writeText(document.getElementById("suggestions_text").innerText).then(() => alert("Texto copiado al portapapeles"))'>&nbsp;✂&nbsp;</button>
256
  </div>
 
274
  html_output += "</ul><h4>Top 10 Sugerencias de Qwant:</h4><ul>"
275
  for suggestion, freq in qwant_top_10:
276
  html_output += f"<li>{suggestion} ({freq})</li>"
277
+ html_output += "</ul><h4>Top 10 Sugerencias de Brave:</h4><ul>"
278
+ for suggestion, freq in brave_top_10:
279
+ html_output += f"<li>{suggestion} ({freq})</li>"
280
  html_output += "</ul>"
281
 
282
  return html_output