Add1E commited on
Commit
05bad3c
·
verified ·
1 Parent(s): 879fcaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -30
app.py CHANGED
@@ -9,8 +9,6 @@ import hmac
9
  import os
10
  import time
11
 
12
- feed_url1 = 'https://trends.google.de/trends/trendingsearches/daily/rss?geo=AT'
13
-
14
  def parse_url(url):
15
  response = requests.get(url)
16
 
@@ -118,20 +116,19 @@ def display_trends_from_yesterday():
118
  def display_articles_for_category(category):
119
  checkbox_statuses = {}
120
  urls = []
121
-
122
  # Dictionary zur Verwaltung des Status jeder Checkbox
123
- for index, row in st.session_state["real_trending_searches"][category].iterrows():
124
- articles = find_details(st.session_state["base_data"][category], row['title'])
125
  for count2, url in enumerate(articles, start=1):
126
  checkbox_label = f"{category}_{index}_{count2}"
127
  if st.session_state.reset:
128
  st.session_state[checkbox_label] = False
129
  checkbox_statuses[checkbox_label] = st.session_state.get(checkbox_label, False)
130
 
131
- for index, row in st.session_state["real_trending_searches"][category].iterrows():
132
  count = index + 1
133
  with st.expander(f"{count}• {row['title']} "):
134
- articles = find_details(st.session_state["base_data"][category], row['title'])
135
  for count2, url in enumerate(articles, start=1):
136
  checkbox_label = f"{category}_{index}_{count2}"
137
  disabled = not checkbox_statuses[checkbox_label] and sum(checkbox_statuses.values()) >= MAX_CHECKED
@@ -192,6 +189,32 @@ categories = {
192
  "Technik": "t",
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  MAX_CHECKED = 3
196
 
197
  def check_password():
@@ -221,46 +244,39 @@ def check_password():
221
  if not check_password():
222
  st.stop() # Do not continue if check_password is not True.
223
 
224
- pytrend = TrendReq(hl='de-AT', tz=360, timeout=(10,50))
225
 
226
- if 'base_load_finished' not in st.session_state:
227
- st.session_state["real_trending_searches"] = {}
228
- st.session_state["base_data"] = {}
229
- for category_name, category_code in categories.items():
230
- if 'base_load_finished' not in st.session_state:
231
- st.session_state["base"] = pytrend.realtime_trending_searches(pn='AT', cat=category_code, count=75)
232
- st.session_state["base_data"][category_name] = st.session_state["base"]
233
- st.session_state["real_trending_searches"][category_name] = convert_into_pd(st.session_state["base"])
234
- elif st.session_state.reset:
235
- st.session_state["base"] = pytrend.realtime_trending_searches(pn='AT', cat=category_code, count=75)
236
- st.session_state["base_data"][category_name] = st.session_state["base"]
237
- st.session_state["real_trending_searches"][category_name] = convert_into_pd(st.session_state["base"])
238
 
239
  if 'selected_option' not in st.session_state:
240
  st.session_state['selected_option'] = "default_value" # You can set a default value as needed
241
 
242
  # Now, you can safely use st.session_state['selected_option']
 
 
 
 
 
 
 
 
 
 
 
243
  selected_option = st.sidebar.radio("Choose an option", ["Realzeit Anfragen", "Tagesaktuelle Anfragen", "Trends von Gestern"])
244
  st.warning("Die aufgelisteten Keywörter für erhöhte Reichweite in den Überschriften verwenden")
245
  if selected_option == "Tagesaktuelle Anfragen":
246
- if 'today' not in st.session_state:
247
- st.session_state["today"] = pytrend.today_searches(pn="AT")
248
- elif st.session_state.reset:
249
- st.session_state["today"] = pytrend.today_searches(pn="AT")
250
-
251
- #today = pytrend.today_searches(pn="AT")
252
- #trending_searches = pytrend.trending_searches(pn="austria")
253
- for count, index in enumerate(st.session_state["today"], start=0):
254
  try:
255
  display_articles_for_today(count, index)
256
  except Exception as e:
257
  st.code(e)
258
  continue
259
  elif selected_option == "Realzeit Anfragen":
260
- choices_list = list(st.session_state["real_trending_searches"].keys())
261
  if len(categories) == len(choices_list):
262
  st.session_state["base_load_finished"] = True
263
- print(choices_list)
264
  auswahl = st.selectbox("Select Ressort", choices_list)
265
 
266
  display_articles_for_category(auswahl)
 
9
  import os
10
  import time
11
 
 
 
12
  def parse_url(url):
13
  response = requests.get(url)
14
 
 
116
  def display_articles_for_category(category):
117
  checkbox_statuses = {}
118
  urls = []
 
119
  # Dictionary zur Verwaltung des Status jeder Checkbox
120
+ for index, row in st.session_state["real_trending_searches"][selected_country][category].iterrows():
121
+ articles = find_details(st.session_state["base_data"][selected_country][category], row['title'])
122
  for count2, url in enumerate(articles, start=1):
123
  checkbox_label = f"{category}_{index}_{count2}"
124
  if st.session_state.reset:
125
  st.session_state[checkbox_label] = False
126
  checkbox_statuses[checkbox_label] = st.session_state.get(checkbox_label, False)
127
 
128
+ for index, row in st.session_state["real_trending_searches"][selected_country][category].iterrows():
129
  count = index + 1
130
  with st.expander(f"{count}• {row['title']} "):
131
+ articles = find_details(st.session_state["base_data"][selected_country][category], row['title'])
132
  for count2, url in enumerate(articles, start=1):
133
  checkbox_label = f"{category}_{index}_{count2}"
134
  disabled = not checkbox_statuses[checkbox_label] and sum(checkbox_statuses.values()) >= MAX_CHECKED
 
189
  "Technik": "t",
190
  }
191
 
192
+ country_list = {
193
+ "Germamy" : "DE",
194
+ "Austria" : "AT"
195
+ }
196
+
197
+ pytrend = TrendReq(hl='de-AT', tz=360, timeout=(10,50))
198
+
199
+ if 'base_load_finished' not in st.session_state:
200
+ st.session_state["real_trending_searches"] = {}
201
+ st.session_state["base_data"] = {}
202
+ st.session_state["pn"] = "AT"
203
+
204
+ if 'base_load_finished' not in st.session_state or st.session_state.reset:
205
+ with st.spinner("Loading Trends"):
206
+ st.session_state["today"] = {}
207
+ for country_name, pn_option in country_list.items():
208
+ st.session_state["base_data"][pn_option] = {}
209
+ st.session_state["real_trending_searches"][pn_option] = {}
210
+ st.session_state["today"][pn_option] = pytrend.today_searches(pn=pn_option)
211
+
212
+ for category_name, category_code in categories.items():
213
+ st.session_state["base"] = pytrend.realtime_trending_searches(pn=pn_option, cat=category_code, count=75)
214
+ st.session_state["base_data"][pn_option][category_name] = st.session_state["base"]
215
+ st.session_state["real_trending_searches"][pn_option][category_name] = convert_into_pd(st.session_state["base"])
216
+
217
+
218
  MAX_CHECKED = 3
219
 
220
  def check_password():
 
244
  if not check_password():
245
  st.stop() # Do not continue if check_password is not True.
246
 
 
247
 
248
+
249
+
 
 
 
 
 
 
 
 
 
 
250
 
251
  if 'selected_option' not in st.session_state:
252
  st.session_state['selected_option'] = "default_value" # You can set a default value as needed
253
 
254
  # Now, you can safely use st.session_state['selected_option']
255
+ # Selectbox to choose a country
256
+ selected_country = st.sidebar.selectbox("Choose a Country", ["AT", "DE"])
257
+ feed_url1 = f'https://trends.google.de/trends/trendingsearches/daily/rss?geo={selected_country}'
258
+
259
+ # Button to trigger actions
260
+ if st.sidebar.button("Change Country"):
261
+ if selected_country == "AT":
262
+ st.session_state["pn"] = selected_country
263
+ elif selected_country == "DE":
264
+ st.session_state["pn"] = selected_country
265
+
266
  selected_option = st.sidebar.radio("Choose an option", ["Realzeit Anfragen", "Tagesaktuelle Anfragen", "Trends von Gestern"])
267
  st.warning("Die aufgelisteten Keywörter für erhöhte Reichweite in den Überschriften verwenden")
268
  if selected_option == "Tagesaktuelle Anfragen":
269
+
270
+ for count, index in enumerate(st.session_state["today"][selected_country], start=0):
 
 
 
 
 
 
271
  try:
272
  display_articles_for_today(count, index)
273
  except Exception as e:
274
  st.code(e)
275
  continue
276
  elif selected_option == "Realzeit Anfragen":
277
+ choices_list = list(st.session_state["real_trending_searches"][selected_country].keys())
278
  if len(categories) == len(choices_list):
279
  st.session_state["base_load_finished"] = True
 
280
  auswahl = st.selectbox("Select Ressort", choices_list)
281
 
282
  display_articles_for_category(auswahl)