Update app.py
Browse files28 unmodified lines2930313233343536373839404142434445464748495051525354555657585928 unmodified linesreturn Nonedef parse_input_and_schedule(input_text):"""Parse user input and schedule the event."""# Use dateparser to parse natural language datesparsed_date = dateparser.parse(input_text,settings={'PREFER_DATES_FROM': 'future', # Prefer future dates})if not parsed_date:st.error("Could not parse the date and time. Please try a format like 'tomorrow at 5pm'.")return# Extract the title and datetimewords = input_text.split()title = " ".join(words[:-3]) # Extract the title excluding time-related keywordsdatetime_string = parsed_date.isoformat()# Debugging outputst.write(f"Parsed Event: {title}, Scheduled Time: {parsed_date}")# Add event to Google Calendar (placeholder for actual API integration)st.success(f"Event '{title}' scheduled for {parsed_date}!")# Streamlit Appst.title("Smart Scheduler with Google Calendar")28 unmodified lines293031323334353637383940414243444546474849505152535455565758596028 unmodified linesreturn Nonedef parse_input_and_schedule(input_text):"""Parse user input for title and datetime, then schedule the event."""# Split the input into words and extract the event title and date/time# Assume the title is the part of the input before the datewords = input_text.split(' at ') # Splitting around 'at' to separate title and time partif len(words) < 2:st.error("Could not parse the event. Make sure to specify the title and time (e.g., 'gym time for tomorrow at 6pm').")returntitle = words[0].strip() # The event titledate_input = ' at '.join(words[1:]).strip() # The time portion, including relative date# Parse the date/time using dateparserparsed_date = dateparser.parse(date_input, settings={'PREFER_DATES_FROM': 'future'})if not parsed_date:st.error(f"Could not parse the date and time: {date_input}. Please try again.")return# Show the parsed event detailsst.write(f"Event Title: {title}")st.write(f"Scheduled Time: {parsed_date}")# Add event to Google Calendar (this would be the integration part)st.success(f"Event '{title}' scheduled for {parsed_date}!")# Streamlit Appst.title("Smart Scheduler with Google Calendar")
app.py+22-21