Spaces:
Runtime error
Runtime error
File size: 9,797 Bytes
5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a f015802 5a25a6a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | import gradio as gr
import datetime
import pytz
from datetime import datetime, timedelta
import calendar
def get_next_qa_dates():
"""Calculate the next 4 Q&A sessions (every other Wednesday at 8pm EST)"""
est = pytz.timezone('US/Eastern')
now = datetime.now(est)
qa_dates = []
# Define the base date - August 6, 2025 at 8pm EST (a known meeting date)
base_date = est.localize(datetime(2025, 8, 6, 20, 0))
# If we're past the base date, find the next Wednesday that would be in the sequence
if now > base_date:
# Calculate how many weeks have passed since the base date
days_passed = (now.date() - base_date.date()).days
weeks_passed = days_passed // 14 # Every 2 weeks
# Get the next meeting date in the sequence
next_meeting = base_date + timedelta(weeks=weeks_passed * 2)
# If we've already passed this meeting, go to the next one
if now > next_meeting:
next_meeting += timedelta(weeks=2)
else:
next_meeting = base_date
# Generate the next 4 meeting dates (every 2 weeks)
for i in range(4):
qa_date = next_meeting + timedelta(weeks=i * 2)
qa_dates.append(qa_date)
return qa_dates
def convert_to_user_timezone(qa_dates, user_timezone):
"""Convert Q&A dates to user's timezone"""
try:
user_tz = pytz.timezone(user_timezone)
converted_dates = []
for date in qa_dates:
user_time = date.astimezone(user_tz)
converted_dates.append(user_time)
return converted_dates
except:
return None
def format_datetime_for_calendar(dt):
"""Format datetime for calendar export"""
return dt.strftime("%Y%m%dT%H%M%S")
def create_calendar_link(dt, timezone_name):
"""Create Google Calendar link"""
start_time = format_datetime_for_calendar(dt)
end_time = format_datetime_for_calendar(dt + timedelta(hours=1))
title = "Wendy Day Live Q&A Session"
details = f"Live Q&A mentoring session with music industry legend Wendy Day. Time shown in {timezone_name}."
google_cal_url = f"https://calendar.google.com/calendar/render?action=TEMPLATE&text={title}&dates={start_time}/{end_time}&details={details}"
return google_cal_url
def get_timezone_info(timezone_selection):
"""Main function to get timezone info and next Q&A times"""
if not timezone_selection:
return "Please select your timezone first! π", "", ""
# Get next Q&A dates in EST
qa_dates = get_next_qa_dates()
# Convert to user timezone
user_dates = convert_to_user_timezone(qa_dates, timezone_selection)
if user_dates is None:
return "Error: Invalid timezone selected. Please try again! β οΈ", "", ""
# Format the response
next_qa = user_dates[0]
# Check if the next Q&A is today
est = pytz.timezone('US/Eastern')
now = datetime.now(est)
is_today = next_qa.date() == now.date()
# Calculate time until next Q&A
time_until = next_qa - datetime.now(pytz.timezone(timezone_selection))
days_until = time_until.days
hours_until = time_until.seconds // 3600
minutes_until = (time_until.seconds % 3600) // 60
# Format time until message
if is_today:
if hours_until > 0:
time_message = f"*That's in {hours_until} hours and {minutes_until} minutes!* π"
elif minutes_until > 0:
time_message = f"*Starting in {minutes_until} minutes!* π"
else:
time_message = "*The session has already started or just ended!*"
elif days_until == 0:
time_message = f"*That's tomorrow!*"
else:
time_message = f"*That's in {days_until} days!*"
# Main response with next Q&A
main_response = f"""
## π΅ Next Live Q&A with Wendy Day
**π
{next_qa.strftime('%A, %B %d, %Y')}**
**π {next_qa.strftime('%I:%M %p')} ({timezone_selection})**
{time_message}
---
### π Add to Your Calendar
Click the link below to add this event to Google Calendar:
"""
# Create calendar link
calendar_link = create_calendar_link(next_qa, timezone_selection)
# Upcoming sessions
upcoming_sessions = "### ποΈ All Upcoming Sessions:\n\n"
for i, date in enumerate(user_dates, 1):
upcoming_sessions += f"**{i}.** {date.strftime('%A, %B %d, %Y at %I:%M %p')}\n"
upcoming_sessions += "\n*Sessions occur every other Wednesday at 8pm EST*"
return main_response, calendar_link, upcoming_sessions
# Common timezone options
TIMEZONE_OPTIONS = [
"US/Eastern", "US/Central", "US/Mountain", "US/Pacific",
"Europe/London", "Europe/Paris", "Europe/Berlin", "Europe/Rome",
"Asia/Tokyo", "Asia/Shanghai", "Asia/Mumbai", "Asia/Dubai",
"Australia/Sydney", "Australia/Melbourne", "Australia/Perth",
"Canada/Eastern", "Canada/Central", "Canada/Mountain", "Canada/Pacific",
"America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
"America/Toronto", "America/Vancouver", "America/Mexico_City",
"Europe/Amsterdam", "Europe/Stockholm", "Europe/Madrid",
"Asia/Seoul", "Asia/Singapore", "Asia/Bangkok", "Asia/Jakarta",
"Africa/Cairo", "Africa/Johannesburg", "Africa/Lagos",
"Pacific/Auckland", "Pacific/Honolulu"
]
# Custom CSS for beautiful styling
custom_css = """
.gradio-container {
max-width: 800px !important;
margin: auto !important;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
padding: 20px !important;
border-radius: 15px !important;
}
.gr-form {
background: rgba(255, 255, 255, 0.95) !important;
border-radius: 15px !important;
padding: 30px !important;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
}
.gr-button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
border: none !important;
color: white !important;
font-weight: bold !important;
border-radius: 25px !important;
padding: 15px 30px !important;
transition: all 0.3s ease !important;
}
.gr-button:hover {
transform: translateY(-2px) !important;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
}
.gr-textbox, .gr-dropdown {
border-radius: 10px !important;
border: 2px solid #e0e0e0 !important;
transition: all 0.3s ease !important;
}
.gr-textbox:focus, .gr-dropdown:focus {
border-color: #667eea !important;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
}
h1 {
color: #2d3748 !important;
text-align: center !important;
font-size: 2.5rem !important;
margin-bottom: 10px !important;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1) !important;
}
.description {
text-align: center !important;
color: #4a5568 !important;
font-size: 1.1rem !important;
margin-bottom: 30px !important;
}
.gr-markdown {
background: rgba(255, 255, 255, 0.8) !important;
border-radius: 10px !important;
padding: 20px !important;
margin: 10px 0 !important;
}
"""
# Create the Gradio interface
with gr.Blocks(css=custom_css, title="Wendy Day Q&A Time Finder") as app:
gr.HTML("<h1>π΅ Wendy Day Live Q&A Time Finder</h1>")
gr.HTML("<p class='description'>Never miss another mentoring session! Find out when the next Live Q&A happens in your timezone.</p>")
with gr.Row():
with gr.Column(scale=2):
timezone_dropdown = gr.Dropdown(
choices=TIMEZONE_OPTIONS,
label="π Select Your Timezone",
value=None
)
check_button = gr.Button("π Find My Next Q&A Time", variant="primary", size="lg")
with gr.Row():
with gr.Column():
result_text = gr.Markdown(label="π
Your Next Q&A Time")
calendar_link = gr.HTML(label="π Add to Calendar")
upcoming_text = gr.Markdown(label="ποΈ Upcoming Sessions")
# Event handler
def handle_timezone_selection(timezone_sel):
main_text, cal_link, upcoming = get_timezone_info(timezone_sel)
# Format calendar link as clickable button
if cal_link:
cal_html = f"""
<div style="text-align: center; margin: 20px 0;">
<a href="{cal_link}" target="_blank" style="
background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
color: white;
padding: 15px 30px;
border-radius: 25px;
text-decoration: none;
font-weight: bold;
display: inline-block;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
">
π
Add to Google Calendar
</a>
</div>
"""
else:
cal_html = ""
return main_text, cal_html, upcoming
check_button.click(
fn=handle_timezone_selection,
inputs=[timezone_dropdown],
outputs=[result_text, calendar_link, upcoming_text]
)
# Auto-update when timezone is selected
timezone_dropdown.change(
fn=handle_timezone_selection,
inputs=[timezone_dropdown],
outputs=[result_text, calendar_link, upcoming_text]
)
gr.HTML("""
<div style="text-align: center; margin-top: 30px; color: #666; font-size: 0.9rem;">
<p>π Q&A sessions happen every other Wednesday at 8pm EST</p>
<p>π Built with love for Wendy Day's mentoring community</p>
</div>
""")
# Launch the app
if __name__ == "__main__":
app.launch(share=True) |