Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,6 +63,46 @@ def get_current_time_and_date():
|
|
| 63 |
|
| 64 |
current_time_and_date = get_current_time_and_date()
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
def fetch_local_events():
|
| 67 |
api_key = os.environ['SERP_API']
|
| 68 |
url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'
|
|
@@ -72,33 +112,52 @@ def fetch_local_events():
|
|
| 72 |
events_html = """
|
| 73 |
<h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
|
| 74 |
<style>
|
| 75 |
-
|
| 76 |
font-family: 'Verdana', sans-serif;
|
| 77 |
color: #333;
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
font-weight: bold;
|
| 81 |
}
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
color: #1E90FF;
|
| 84 |
text-decoration: none;
|
| 85 |
}
|
| 86 |
-
.event-
|
| 87 |
text-decoration: underline;
|
| 88 |
}
|
| 89 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
"""
|
| 91 |
-
for
|
| 92 |
title = event.get("title", "No title")
|
| 93 |
date = event.get("date", "No date")
|
| 94 |
location = event.get("address", "No location")
|
| 95 |
link = event.get("link", "#")
|
| 96 |
events_html += f"""
|
| 97 |
-
<
|
| 98 |
-
<a href='{link}' target='_blank'>{
|
| 99 |
-
<
|
| 100 |
-
|
|
|
|
| 101 |
"""
|
|
|
|
| 102 |
return events_html
|
| 103 |
else:
|
| 104 |
return "<p>Failed to fetch local events</p>"
|
|
|
|
| 63 |
|
| 64 |
current_time_and_date = get_current_time_and_date()
|
| 65 |
|
| 66 |
+
# def fetch_local_events():
|
| 67 |
+
# api_key = os.environ['SERP_API']
|
| 68 |
+
# url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'
|
| 69 |
+
# response = requests.get(url)
|
| 70 |
+
# if response.status_code == 200:
|
| 71 |
+
# events_results = response.json().get("events_results", [])
|
| 72 |
+
# events_html = """
|
| 73 |
+
# <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
|
| 74 |
+
# <style>
|
| 75 |
+
# .event-item {
|
| 76 |
+
# font-family: 'Verdana', sans-serif;
|
| 77 |
+
# color: #333;
|
| 78 |
+
# margin-bottom: 15px;
|
| 79 |
+
# padding: 10px;
|
| 80 |
+
# font-weight: bold;
|
| 81 |
+
# }
|
| 82 |
+
# .event-item a {
|
| 83 |
+
# color: #1E90FF;
|
| 84 |
+
# text-decoration: none;
|
| 85 |
+
# }
|
| 86 |
+
# .event-item a:hover {
|
| 87 |
+
# text-decoration: underline;
|
| 88 |
+
# }
|
| 89 |
+
# </style>
|
| 90 |
+
# """
|
| 91 |
+
# for index, event in enumerate(events_results):
|
| 92 |
+
# title = event.get("title", "No title")
|
| 93 |
+
# date = event.get("date", "No date")
|
| 94 |
+
# location = event.get("address", "No location")
|
| 95 |
+
# link = event.get("link", "#")
|
| 96 |
+
# events_html += f"""
|
| 97 |
+
# <div class="event-item">
|
| 98 |
+
# <a href='{link}' target='_blank'>{index + 1}. {title}</a>
|
| 99 |
+
# <p>Date: {date}<br>Location: {location}</p>
|
| 100 |
+
# </div>
|
| 101 |
+
# """
|
| 102 |
+
# return events_html
|
| 103 |
+
# else:
|
| 104 |
+
# return "<p>Failed to fetch local events</p>"
|
| 105 |
+
|
| 106 |
def fetch_local_events():
|
| 107 |
api_key = os.environ['SERP_API']
|
| 108 |
url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Birmingham&hl=en&gl=us&api_key={api_key}'
|
|
|
|
| 112 |
events_html = """
|
| 113 |
<h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
|
| 114 |
<style>
|
| 115 |
+
table {
|
| 116 |
font-family: 'Verdana', sans-serif;
|
| 117 |
color: #333;
|
| 118 |
+
border-collapse: collapse;
|
| 119 |
+
width: 100%;
|
|
|
|
| 120 |
}
|
| 121 |
+
th, td {
|
| 122 |
+
border: 1px solid #ddd;
|
| 123 |
+
padding: 8px;
|
| 124 |
+
}
|
| 125 |
+
th {
|
| 126 |
+
background-color: #f2f2f2;
|
| 127 |
+
color: #333;
|
| 128 |
+
text-align: left;
|
| 129 |
+
}
|
| 130 |
+
tr:hover {
|
| 131 |
+
background-color: #f5f5f5;
|
| 132 |
+
}
|
| 133 |
+
.event-link {
|
| 134 |
color: #1E90FF;
|
| 135 |
text-decoration: none;
|
| 136 |
}
|
| 137 |
+
.event-link:hover {
|
| 138 |
text-decoration: underline;
|
| 139 |
}
|
| 140 |
</style>
|
| 141 |
+
<table>
|
| 142 |
+
<tr>
|
| 143 |
+
<th>Title</th>
|
| 144 |
+
<th>Date</th>
|
| 145 |
+
<th>Location</th>
|
| 146 |
+
</tr>
|
| 147 |
"""
|
| 148 |
+
for event in events_results:
|
| 149 |
title = event.get("title", "No title")
|
| 150 |
date = event.get("date", "No date")
|
| 151 |
location = event.get("address", "No location")
|
| 152 |
link = event.get("link", "#")
|
| 153 |
events_html += f"""
|
| 154 |
+
<tr>
|
| 155 |
+
<td><a class='event-link' href='{link}' target='_blank'>{title}</a></td>
|
| 156 |
+
<td>{date}</td>
|
| 157 |
+
<td>{location}</td>
|
| 158 |
+
</tr>
|
| 159 |
"""
|
| 160 |
+
events_html += "</table>"
|
| 161 |
return events_html
|
| 162 |
else:
|
| 163 |
return "<p>Failed to fetch local events</p>"
|