Pijush2023 commited on
Commit
c2c9ec8
·
verified ·
1 Parent(s): afbcc05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -4
app.py CHANGED
@@ -169,19 +169,87 @@ def generate_map(location_names):
169
  def fetch_local_news():
170
  api_key = os.environ['SERP_API']
171
  url = f'https://serpapi.com/search.json?engine=google_news&q=ohama headline&api_key={api_key}'
172
-
173
- response = requests.get(url)
 
174
  if response.status_code == 200:
175
  results = response.json().get("news_results", [])
176
- news_html = "<h2>Omaha Today Headline </h2>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  for index, result in enumerate(results[:10]):
178
  title = result.get("title", "No title")
179
  link = result.get("link", "#")
180
  snippet = result.get("snippet", "")
181
- news_html += f"<p>{index + 1}. <a href='{link}' target='_blank'>{title}</a><br>{snippet}</p>"
 
 
 
 
 
182
  return news_html
183
  else:
184
  return "<p>Failed to fetch local news</p>"
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
  # Function to fetch local events
187
  def fetch_local_events():
 
169
  def fetch_local_news():
170
  api_key = os.environ['SERP_API']
171
  url = f'https://serpapi.com/search.json?engine=google_news&q=ohama headline&api_key={api_key}'
172
+
173
+
174
+ response = requests.get(url)
175
  if response.status_code == 200:
176
  results = response.json().get("news_results", [])
177
+ news_html = """
178
+ <h2 style="font-family: Arial, sans-serif; color: #4CAF50;">Omaha Today Headlines</h2>
179
+ <style>
180
+ .news-item {
181
+ font-family: Arial, sans-serif;
182
+ color: #333;
183
+ margin-bottom: 15px;
184
+ padding: 10px;
185
+ border: 1px solid #ddd;
186
+ border-radius: 5px;
187
+ transition: box-shadow 0.3s ease;
188
+ }
189
+ .news-item:hover {
190
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
191
+ }
192
+ .news-item a {
193
+ color: #1E90FF;
194
+ text-decoration: none;
195
+ }
196
+ .news-item a:hover {
197
+ text-decoration: underline;
198
+ }
199
+ .news-preview {
200
+ position: absolute;
201
+ display: none;
202
+ border: 1px solid #ccc;
203
+ border-radius: 5px;
204
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
205
+ background-color: white;
206
+ z-index: 1000;
207
+ max-width: 300px;
208
+ padding: 10px;
209
+ font-family: Arial, sans-serif;
210
+ color: #333;
211
+ }
212
+ </style>
213
+ <script>
214
+ function showPreview(event, previewContent) {
215
+ var previewBox = document.getElementById('news-preview');
216
+ previewBox.innerHTML = previewContent;
217
+ previewBox.style.left = event.pageX + 'px';
218
+ previewBox.style.top = event.pageY + 'px';
219
+ previewBox.style.display = 'block';
220
+ }
221
+ function hidePreview() {
222
+ var previewBox = document.getElementById('news-preview');
223
+ previewBox.style.display = 'none';
224
+ }
225
+ </script>
226
+ <div id="news-preview" class="news-preview"></div>
227
+ """
228
  for index, result in enumerate(results[:10]):
229
  title = result.get("title", "No title")
230
  link = result.get("link", "#")
231
  snippet = result.get("snippet", "")
232
+ news_html += f"""
233
+ <div class="news-item" onmouseover="showPreview(event, '{snippet}')" onmouseout="hidePreview()">
234
+ <a href='{link}' target='_blank'>{index + 1}. {title}</a>
235
+ <p>{snippet}</p>
236
+ </div>
237
+ """
238
  return news_html
239
  else:
240
  return "<p>Failed to fetch local news</p>"
241
+ # response = requests.get(url)
242
+ # if response.status_code == 200:
243
+ # results = response.json().get("news_results", [])
244
+ # news_html = "<h2>Omaha Today Headline </h2>"
245
+ # for index, result in enumerate(results[:10]):
246
+ # title = result.get("title", "No title")
247
+ # link = result.get("link", "#")
248
+ # snippet = result.get("snippet", "")
249
+ # news_html += f"<p>{index + 1}. <a href='{link}' target='_blank'>{title}</a><br>{snippet}</p>"
250
+ # return news_html
251
+ # else:
252
+ # return "<p>Failed to fetch local news</p>"
253
 
254
  # Function to fetch local events
255
  def fetch_local_events():