Spaces:
Runtime error
Runtime error
Upload app.py
Browse filesfixing scheduling logic
4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505142 unmodified lines9495969798991 unmodified line1011021031041051061079 unmodified lines117118119120121122143 unmodified lines2662672682692702712724 unmodified linesimport calendardef get_next_qa_dates():"""Calculate the next 4 Q&A sessions (2nd and 4th Wednesday of each month at 8pm EST)"""est = pytz.timezone('US/Eastern')now = datetime.now(est)qa_dates = []# Start from current month and look ahead 3 months to ensure we get next 4 sessionscurrent_month = now.monthcurrent_year = now.yearfor month_offset in range(4): # Look ahead 4 months to be safemonth = current_month + month_offsetyear = current_year# Handle year overflowif month > 12:month = month - 12year += 1# Get the first day of the monthfirst_day = datetime(year, month, 1)# Find the first Wednesday of the monthdays_until_wednesday = (2 - first_day.weekday()) % 7first_wednesday = first_day + timedelta(days=days_until_wednesday)# Calculate 2nd and 4th Wednesdaysecond_wednesday = first_wednesday + timedelta(days=7)fourth_wednesday = first_wednesday + timedelta(days=21)# Create datetime objects with 8pm ESTsecond_qa = est.localize(datetime(year, month, second_wednesday.day, 20, 0))fourth_qa = est.localize(datetime(year, month, fourth_wednesday.day, 20, 0))qa_dates.extend([second_qa, fourth_qa])# Filter out past dates and sortfuture_dates = [date for date in qa_dates if date > now]future_dates.sort()return future_dates[:4] # Return next 4 sessionsdef convert_to_user_timezone(qa_dates, user_timezone):"""Convert Q&A dates to user's timezone"""42 unmodified lines# Format the responsenext_qa = user_dates[0]# Main response with next Q&Amain_response = f"""## π΅ Next Live Q&A with Wendy Day1 unmodified line**π {next_qa.strftime('%A, %B %d, %Y')}****π {next_qa.strftime('%I:%M %p')} ({timezone_selection})***That's in {(next_qa.date() - datetime.now().date()).days} days!*---9 unmodified linesfor i, date in enumerate(user_dates, 1):upcoming_sessions += f"**{i}.** {date.strftime('%A, %B %d, %Y at %I:%M %p')}\n"return main_response, calendar_link, upcoming_sessions# Common timezone options143 unmodified linesgr.HTML("""<div style="text-align: center; margin-top: 30px; color: #666; font-size: 0.9rem;"><p>π Q&A sessions happen on the 2nd and 4th Wednesday of every month at 8pm EST</p><p>π Built with love for Wendy Day's mentoring community</p></div>""")4 unmodified lines567891011121314151617181920212223242526272829303132333435363738394042 unmodified lines83848586878889909192939495969798991001011021031041051061071081091101111121 unmodified line1141151161171181191209 unmodified lines130131132133134135136137143 unmodified lines2812822832842852862874 unmodified linesimport calendardef 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 sequenceif now > base_date:# Calculate how many weeks have passed since the base datedays_passed = (now.date() - base_date.date()).daysweeks_passed = days_passed // 14 # Every 2 weeks# Get the next meeting date in the sequencenext_meeting = base_date + timedelta(weeks=weeks_passed * 2)# If we've already passed this meeting, go to the next oneif 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_datesdef convert_to_user_timezone(qa_dates, user_timezone):"""Convert Q&A dates to user's timezone"""42 unmodified lines# Format the responsenext_qa = user_dates[0]# Check if the next Q&A is todayest = pytz.timezone('US/Eastern')now = datetime.now(est)is_today = next_qa.date() == now.date()# Calculate time until next Q&Atime_until = next_qa - datetime.now(pytz.timezone(timezone_selection))days_until = time_until.dayshours_until = time_until.seconds // 3600minutes_until = (time_until.seconds % 3600) // 60# Format time until messageif 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&Amain_response = f"""## π΅ Next Live Q&A with Wendy Day1 unmodified line**π {next_qa.strftime('%A, %B %d, %Y')}****π {next_qa.strftime('%I:%M %p')} ({timezone_selection})**{time_message}---9 unmodified linesfor 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 options143 unmodified linesgr.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>""")
app.py+48-33