Spaces:
Runtime error

LiveTimeFinder / app.py
Erinem's picture
Upload app.py
f015802 verified
Raw History Blame Contribute Delete
9.8 kB
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)