Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
from pytrends.request import TrendReq
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import xml.etree.ElementTree as ET
|
@@ -9,9 +8,31 @@ import hmac
|
|
9 |
import os
|
10 |
import time
|
11 |
from PIL import Image
|
12 |
-
from
|
|
|
13 |
import re
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def parse_url(url):
|
17 |
response = requests.get(url)
|
@@ -157,8 +178,7 @@ def display_articles_for_category(category):
|
|
157 |
checkbox_statuses = {}
|
158 |
urls = []
|
159 |
|
160 |
-
|
161 |
-
trending_data = st.session_state["real_trending_searches"][selected_country][category]
|
162 |
|
163 |
if st.session_state.get("reset", False):
|
164 |
for idx, (topic, data) in enumerate(trending_data.items()):
|
@@ -234,8 +254,6 @@ country_list = {
|
|
234 |
"Austria" : "AT"
|
235 |
}
|
236 |
|
237 |
-
pytrend = TrendReq(hl='de-AT', tz=360, timeout=(10,50))
|
238 |
-
|
239 |
if 'base_load_finished' not in st.session_state:
|
240 |
st.session_state["real_trending_searches"] = {}
|
241 |
st.session_state["base_data"] = {}
|
@@ -248,13 +266,11 @@ if 'base_load_finished' not in st.session_state or st.session_state.reset:
|
|
248 |
for country_name, pn_option in country_list.items():
|
249 |
st.session_state["base_data"][pn_option] = {}
|
250 |
st.session_state["real_trending_searches"][pn_option] = {}
|
251 |
-
|
252 |
-
|
253 |
-
st.session_state["base"][pn_option] = crawl_url(url=f"https://trends.google.com/trends/trendingsearches/daily?geo={pn_option}&category=2")
|
254 |
-
st.session_state["real_trending_searches"][pn_option] = convert_into_dict(st.session_state["base"][pn_option])
|
255 |
-
print(f"{country_name} finished")
|
256 |
st.session_state["base_load_finished"]= True
|
257 |
|
|
|
258 |
MAX_CHECKED = 3
|
259 |
|
260 |
def check_password():
|
@@ -310,12 +326,11 @@ fixed_order = [
|
|
310 |
]
|
311 |
|
312 |
if 'selected_option' not in st.session_state:
|
313 |
-
st.session_state['selected_option'] = "default_value"
|
314 |
|
315 |
img = Image.open(r"heute_tensora.png")
|
316 |
st.sidebar.image(img)
|
317 |
|
318 |
-
# Now, you can safely use st.session_state['selected_option']
|
319 |
# Selectbox to choose a country
|
320 |
selected_country = st.sidebar.selectbox("Choose a Country", ["AT", "DE"])
|
321 |
feed_url1 = f'https://trends.google.de/trends/trendingsearches/daily/rss?geo={selected_country}'
|
@@ -340,16 +355,12 @@ st.warning("Die aufgelisteten Keywörter für erhöhte Reichweite in den Übersc
|
|
340 |
# continue
|
341 |
|
342 |
if selected_option == "Realzeit Anfragen":
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
choices_list = [category for category in fixed_order if category in cleaned_to_raw_mapping]
|
349 |
-
|
350 |
-
auswahl = st.selectbox("Select Ressort", choices_list, index=0)
|
351 |
|
352 |
-
display_articles_for_category(
|
353 |
|
354 |
elif selected_option == "Trends von Gestern":
|
355 |
st.error("Aktuell nicht Erreichbar")
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import xml.etree.ElementTree as ET
|
|
|
8 |
import os
|
9 |
import time
|
10 |
from PIL import Image
|
11 |
+
from trend_crawl import get_trends
|
12 |
+
|
13 |
import re
|
14 |
|
15 |
+
TREND_TOPICS = {
|
16 |
+
1: "Autos and Vehicles",
|
17 |
+
2: "Beauty and Fashion",
|
18 |
+
3: "Business and Finance",
|
19 |
+
20: "Climate",
|
20 |
+
4: "Entertainment",
|
21 |
+
5: "Food and Drink",
|
22 |
+
6: "Games",
|
23 |
+
7: "Health",
|
24 |
+
8: "Hobbies and Leisure",
|
25 |
+
9: "Jobs and Education",
|
26 |
+
10: "Law and Government",
|
27 |
+
11: "Other",
|
28 |
+
13: "Pets and Animals",
|
29 |
+
14: "Politics",
|
30 |
+
15: "Science",
|
31 |
+
16: "Shopping",
|
32 |
+
17: "Sports",
|
33 |
+
18: "Technology",
|
34 |
+
19: "Travel and Transportation"
|
35 |
+
}
|
36 |
|
37 |
def parse_url(url):
|
38 |
response = requests.get(url)
|
|
|
178 |
checkbox_statuses = {}
|
179 |
urls = []
|
180 |
|
181 |
+
trending_data = st.session_state["real_trending_searches"][selected_country][selected_country][category]
|
|
|
182 |
|
183 |
if st.session_state.get("reset", False):
|
184 |
for idx, (topic, data) in enumerate(trending_data.items()):
|
|
|
254 |
"Austria" : "AT"
|
255 |
}
|
256 |
|
|
|
|
|
257 |
if 'base_load_finished' not in st.session_state:
|
258 |
st.session_state["real_trending_searches"] = {}
|
259 |
st.session_state["base_data"] = {}
|
|
|
266 |
for country_name, pn_option in country_list.items():
|
267 |
st.session_state["base_data"][pn_option] = {}
|
268 |
st.session_state["real_trending_searches"][pn_option] = {}
|
269 |
+
st.session_state["real_trending_searches"][pn_option] = get_trends([pn_option])
|
270 |
+
|
|
|
|
|
|
|
271 |
st.session_state["base_load_finished"]= True
|
272 |
|
273 |
+
|
274 |
MAX_CHECKED = 3
|
275 |
|
276 |
def check_password():
|
|
|
326 |
]
|
327 |
|
328 |
if 'selected_option' not in st.session_state:
|
329 |
+
st.session_state['selected_option'] = "default_value"
|
330 |
|
331 |
img = Image.open(r"heute_tensora.png")
|
332 |
st.sidebar.image(img)
|
333 |
|
|
|
334 |
# Selectbox to choose a country
|
335 |
selected_country = st.sidebar.selectbox("Choose a Country", ["AT", "DE"])
|
336 |
feed_url1 = f'https://trends.google.de/trends/trendingsearches/daily/rss?geo={selected_country}'
|
|
|
355 |
# continue
|
356 |
|
357 |
if selected_option == "Realzeit Anfragen":
|
358 |
+
available_topics = st.session_state["real_trending_searches"][selected_country][selected_country].keys()
|
359 |
+
filtered_topics = [topic for topic in TREND_TOPICS.values() if topic in available_topics]
|
360 |
+
all_topics = ["All categories"] + filtered_topics
|
361 |
+
auswahl = st.selectbox("Select Ressort", all_topics, index=0)
|
|
|
|
|
|
|
|
|
362 |
|
363 |
+
display_articles_for_category(auswahl)
|
364 |
|
365 |
elif selected_option == "Trends von Gestern":
|
366 |
st.error("Aktuell nicht Erreichbar")
|