Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import requests
|
|
| 3 |
import urllib.parse
|
| 4 |
import re
|
| 5 |
import xmltodict
|
| 6 |
-
import inflect
|
| 7 |
|
| 8 |
# Funci贸n para obtener sugerencias de DuckDuckGo
|
| 9 |
def fetch_duckduckgo_suggestions(query, lang_code="es"):
|
|
@@ -42,9 +41,11 @@ def fetch_youtube_suggestions(query, lang_code="es"):
|
|
| 42 |
|
| 43 |
if response.status_code == 200:
|
| 44 |
try:
|
|
|
|
| 45 |
match = re.search(r'window\.google\.ac\.h\(\["[^"]*",\[(.*?)\],', response.text)
|
| 46 |
if match:
|
| 47 |
suggestions_data = match.group(1)
|
|
|
|
| 48 |
suggestions = re.findall(r'\["([^"]+)"', suggestions_data)
|
| 49 |
return suggestions
|
| 50 |
else:
|
|
@@ -99,6 +100,7 @@ def fetch_amazon_suggestions(query, market_id="ATVPDKIKX0DER", alias="aps"):
|
|
| 99 |
if response.status_code == 200:
|
| 100 |
try:
|
| 101 |
data = response.json()
|
|
|
|
| 102 |
return [item['value'] for item in data.get('suggestions', [])]
|
| 103 |
except ValueError:
|
| 104 |
print("Error decodificando JSON de Amazon")
|
|
@@ -106,27 +108,9 @@ def fetch_amazon_suggestions(query, market_id="ATVPDKIKX0DER", alias="aps"):
|
|
| 106 |
else:
|
| 107 |
return []
|
| 108 |
|
| 109 |
-
# Funci贸n para
|
| 110 |
-
def generate_plural_variations(keyword):
|
| 111 |
-
p = inflect.engine()
|
| 112 |
-
singular = keyword
|
| 113 |
-
plural = p.plural(keyword)
|
| 114 |
-
return [singular, plural]
|
| 115 |
-
|
| 116 |
-
# Funci贸n para expandir la palabra clave con stopwords y conjunciones
|
| 117 |
-
STOP_WORDS = ["de", "en", "por", "para", "con", "sin", "y", "o"]
|
| 118 |
-
|
| 119 |
-
def expand_keyword_with_stopwords(keyword):
|
| 120 |
-
expanded_keywords = [keyword]
|
| 121 |
-
for word in STOP_WORDS:
|
| 122 |
-
expanded_keywords.append(f"{keyword} {word}")
|
| 123 |
-
expanded_keywords.append(f"{word} {keyword}")
|
| 124 |
-
return expanded_keywords
|
| 125 |
-
|
| 126 |
-
# Funci贸n para expandir las palabras clave
|
| 127 |
def expand_keyword(keyword):
|
| 128 |
-
expanded_keywords =
|
| 129 |
-
expanded_keywords += generate_plural_variations(keyword)
|
| 130 |
for letter in 'abcdefghijklmnopqrstuvwxyz*_':
|
| 131 |
expanded_keywords.append(keyword + " " + letter)
|
| 132 |
expanded_keywords.append(letter + " " + keyword)
|
|
@@ -142,32 +126,38 @@ def main(keyword):
|
|
| 142 |
bing_suggestions_all = []
|
| 143 |
amazon_suggestions_all = []
|
| 144 |
|
| 145 |
-
# Obtener sugerencias de
|
| 146 |
for exp_keyword in expanded_keywords:
|
| 147 |
suggestions = fetch_duckduckgo_suggestions(exp_keyword)
|
| 148 |
-
duckduckgo_suggestions_all.extend(suggestions)
|
| 149 |
for suggestion in suggestions:
|
| 150 |
if suggestion in all_suggestions:
|
| 151 |
all_suggestions[suggestion] += 1
|
| 152 |
else:
|
| 153 |
all_suggestions[suggestion] = 1
|
| 154 |
|
|
|
|
|
|
|
| 155 |
suggestions = fetch_google_suggestions(exp_keyword)
|
| 156 |
-
google_suggestions_all.extend(suggestions)
|
| 157 |
for suggestion in suggestions:
|
| 158 |
if suggestion in all_suggestions:
|
| 159 |
all_suggestions[suggestion] += 1
|
| 160 |
else:
|
| 161 |
all_suggestions[suggestion] = 1
|
| 162 |
|
|
|
|
|
|
|
| 163 |
suggestions = fetch_youtube_suggestions(exp_keyword)
|
| 164 |
-
youtube_suggestions_all.extend(suggestions)
|
| 165 |
for suggestion in suggestions:
|
| 166 |
if suggestion in all_suggestions:
|
| 167 |
all_suggestions[suggestion] += 1
|
| 168 |
else:
|
| 169 |
all_suggestions[suggestion] = 1
|
| 170 |
|
|
|
|
|
|
|
| 171 |
suggestions = fetch_bing_suggestions(exp_keyword)
|
| 172 |
bing_suggestions_all.extend(suggestions)
|
| 173 |
for suggestion in suggestions:
|
|
@@ -176,6 +166,8 @@ def main(keyword):
|
|
| 176 |
else:
|
| 177 |
all_suggestions[suggestion] = 1
|
| 178 |
|
|
|
|
|
|
|
| 179 |
suggestions = fetch_amazon_suggestions(exp_keyword)
|
| 180 |
amazon_suggestions_all.extend(suggestions)
|
| 181 |
for suggestion in suggestions:
|
|
@@ -184,14 +176,14 @@ def main(keyword):
|
|
| 184 |
else:
|
| 185 |
all_suggestions[suggestion] = 1
|
| 186 |
|
| 187 |
-
# Filtrar las top 10
|
| 188 |
google_top_10 = list(set(google_suggestions_all))[:10]
|
| 189 |
duckduckgo_top_10 = list(set(duckduckgo_suggestions_all))[:10]
|
| 190 |
youtube_top_10 = list(set(youtube_suggestions_all))[:10]
|
| 191 |
bing_top_10 = list(set(bing_suggestions_all))[:10]
|
| 192 |
amazon_top_10 = list(set(amazon_suggestions_all))[:10]
|
| 193 |
|
| 194 |
-
# Ordenar y filtrar las sugerencias combinadas
|
| 195 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
| 196 |
combined_top_10_suggestions = [sug for sug, freq in sorted_suggestions if freq >= 2][:10]
|
| 197 |
suggestions_str = ", ".join(combined_top_10_suggestions)
|
|
@@ -272,4 +264,4 @@ iface = gr.Interface(
|
|
| 272 |
article="<div style='margin-top:10px'><p style='text-align: center !important; background: #ffffff; padding: 5px 30px; border-radius: 8px; border-width: 1px; border: solid 1px #e5e7eb; width: fit-content; margin: auto;'>Desarrollada por <a style='text-decoration: none !important; color: #e12a31 !important;' href='https://artxeweb.com'>漏 Artxe Web</a></p></div>"
|
| 273 |
)
|
| 274 |
|
| 275 |
-
iface.launch()
|
|
|
|
| 3 |
import urllib.parse
|
| 4 |
import re
|
| 5 |
import xmltodict
|
|
|
|
| 6 |
|
| 7 |
# Funci贸n para obtener sugerencias de DuckDuckGo
|
| 8 |
def fetch_duckduckgo_suggestions(query, lang_code="es"):
|
|
|
|
| 41 |
|
| 42 |
if response.status_code == 200:
|
| 43 |
try:
|
| 44 |
+
# Extraer las sugerencias del formato window.google.ac.h(["..."])
|
| 45 |
match = re.search(r'window\.google\.ac\.h\(\["[^"]*",\[(.*?)\],', response.text)
|
| 46 |
if match:
|
| 47 |
suggestions_data = match.group(1)
|
| 48 |
+
# Extraemos las sugerencias
|
| 49 |
suggestions = re.findall(r'\["([^"]+)"', suggestions_data)
|
| 50 |
return suggestions
|
| 51 |
else:
|
|
|
|
| 100 |
if response.status_code == 200:
|
| 101 |
try:
|
| 102 |
data = response.json()
|
| 103 |
+
# Extraemos las sugerencias desde el JSON bajo la clave 'suggestions'
|
| 104 |
return [item['value'] for item in data.get('suggestions', [])]
|
| 105 |
except ValueError:
|
| 106 |
print("Error decodificando JSON de Amazon")
|
|
|
|
| 108 |
else:
|
| 109 |
return []
|
| 110 |
|
| 111 |
+
# Funci贸n para expandir la palabra clave
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
def expand_keyword(keyword):
|
| 113 |
+
expanded_keywords = [keyword]
|
|
|
|
| 114 |
for letter in 'abcdefghijklmnopqrstuvwxyz*_':
|
| 115 |
expanded_keywords.append(keyword + " " + letter)
|
| 116 |
expanded_keywords.append(letter + " " + keyword)
|
|
|
|
| 126 |
bing_suggestions_all = []
|
| 127 |
amazon_suggestions_all = []
|
| 128 |
|
| 129 |
+
# Obtener sugerencias de DuckDuckGo
|
| 130 |
for exp_keyword in expanded_keywords:
|
| 131 |
suggestions = fetch_duckduckgo_suggestions(exp_keyword)
|
| 132 |
+
duckduckgo_suggestions_all.extend(suggestions) # Agregar todas las sugerencias
|
| 133 |
for suggestion in suggestions:
|
| 134 |
if suggestion in all_suggestions:
|
| 135 |
all_suggestions[suggestion] += 1
|
| 136 |
else:
|
| 137 |
all_suggestions[suggestion] = 1
|
| 138 |
|
| 139 |
+
# Obtener sugerencias de Google
|
| 140 |
+
for exp_keyword in expanded_keywords:
|
| 141 |
suggestions = fetch_google_suggestions(exp_keyword)
|
| 142 |
+
google_suggestions_all.extend(suggestions) # Agregar todas las sugerencias
|
| 143 |
for suggestion in suggestions:
|
| 144 |
if suggestion in all_suggestions:
|
| 145 |
all_suggestions[suggestion] += 1
|
| 146 |
else:
|
| 147 |
all_suggestions[suggestion] = 1
|
| 148 |
|
| 149 |
+
# Obtener sugerencias de YouTube
|
| 150 |
+
for exp_keyword in expanded_keywords:
|
| 151 |
suggestions = fetch_youtube_suggestions(exp_keyword)
|
| 152 |
+
youtube_suggestions_all.extend(suggestions) # Agregar todas las sugerencias
|
| 153 |
for suggestion in suggestions:
|
| 154 |
if suggestion in all_suggestions:
|
| 155 |
all_suggestions[suggestion] += 1
|
| 156 |
else:
|
| 157 |
all_suggestions[suggestion] = 1
|
| 158 |
|
| 159 |
+
# Obtener sugerencias de Bing
|
| 160 |
+
for exp_keyword in expanded_keywords:
|
| 161 |
suggestions = fetch_bing_suggestions(exp_keyword)
|
| 162 |
bing_suggestions_all.extend(suggestions)
|
| 163 |
for suggestion in suggestions:
|
|
|
|
| 166 |
else:
|
| 167 |
all_suggestions[suggestion] = 1
|
| 168 |
|
| 169 |
+
# Obtener sugerencias de Amazon
|
| 170 |
+
for exp_keyword in expanded_keywords:
|
| 171 |
suggestions = fetch_amazon_suggestions(exp_keyword)
|
| 172 |
amazon_suggestions_all.extend(suggestions)
|
| 173 |
for suggestion in suggestions:
|
|
|
|
| 176 |
else:
|
| 177 |
all_suggestions[suggestion] = 1
|
| 178 |
|
| 179 |
+
# Filtrar las top 10 de cada plataforma con su n煤mero de repeticiones
|
| 180 |
google_top_10 = list(set(google_suggestions_all))[:10]
|
| 181 |
duckduckgo_top_10 = list(set(duckduckgo_suggestions_all))[:10]
|
| 182 |
youtube_top_10 = list(set(youtube_suggestions_all))[:10]
|
| 183 |
bing_top_10 = list(set(bing_suggestions_all))[:10]
|
| 184 |
amazon_top_10 = list(set(amazon_suggestions_all))[:10]
|
| 185 |
|
| 186 |
+
# Ordenar y filtrar las sugerencias m谩s frecuentes combinadas
|
| 187 |
sorted_suggestions = sorted(all_suggestions.items(), key=lambda item: item[1], reverse=True)
|
| 188 |
combined_top_10_suggestions = [sug for sug, freq in sorted_suggestions if freq >= 2][:10]
|
| 189 |
suggestions_str = ", ".join(combined_top_10_suggestions)
|
|
|
|
| 264 |
article="<div style='margin-top:10px'><p style='text-align: center !important; background: #ffffff; padding: 5px 30px; border-radius: 8px; border-width: 1px; border: solid 1px #e5e7eb; width: fit-content; margin: auto;'>Desarrollada por <a style='text-decoration: none !important; color: #e12a31 !important;' href='https://artxeweb.com'>漏 Artxe Web</a></p></div>"
|
| 265 |
)
|
| 266 |
|
| 267 |
+
iface.launch()
|