Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CalDAV Tweaks #43

Merged
merged 1 commit into from
May 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions src/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ async def caldav_action(text: str):

task_create_match = re.search(r'\b(?:add|create)\s+a?\s+task\s+called\s+(.+)', text, re.IGNORECASE)
task_delete_match = re.search(r'\b(?:delete|remove)\s+(a )?task\s+called\s+(\w+)', text, re.IGNORECASE)
task_update_match = re.search(r'\b(?:update|change|modify)\s+(a )?task\s+called\s+(\w+)\s+to\s+(\w+)', text, re.IGNORECASE)
tasks_query_match = re.search(r'\b(left|to do|to-do|what else)\b', text, re.IGNORECASE)
completed_tasks_query_match = re.search(r'\bcompleted\s+tasks\b', text, re.IGNORECASE)

Expand All @@ -421,6 +422,16 @@ async def caldav_action(text: str):
""")
return f"Task '{task_name}' created successfully."

elif task_update_match:
task_name = task_update_match.group(2)
new_task_name = task_update_match.group(3)
tasks = calendar.todos()
for task in tasks:
if task_name.lower() in task.instance.vtodo.summary.value.lower():
task.instance.vtodo.summary.value = new_task_name
task.save()
return f"Task '{task_name}' updated to '{new_task_name}' successfully."

elif task_delete_match:
task_name = task_delete_match.group(1)
tasks = calendar.todos()
Expand Down Expand Up @@ -455,6 +466,7 @@ async def caldav_action(text: str):
return "You have no completed tasks."

create_match = re.search(r'\b(?:add|create|schedule)\s+an?\s+(event|appointment)\s+called\s+(\w+)\s+on\s+(\d{4}-\d{2}-\d{2})\s+at\s+(\d{1,2}:\d{2})', text, re.IGNORECASE)
update_match = re.search(r'\b(?:update|change|modify)\s+the\s+(event|appointment)\s+called\s+(\w+)\s+to\s+(\w+)\s+on\s+(\d{4}-\d{2}-\d{2})\s+at\s+(\d{1,2}:\d{2})', text, re.IGNORECASE)
delete_match = re.search(r'\b(?:delete|remove|cancel)\s+the\s+(event|appointment)\s+called\s+(\w+)', text, re.IGNORECASE)
next_event_match = re.search(r"\bwhat'? ?i?s\s+my\s+next\s+(event|appointment)\b", text, re.IGNORECASE)
calendar_query_match = re.search(r"\bwhat'? ?i?s\s+on\s+my\s+calendar\b", text, re.IGNORECASE)
Expand All @@ -466,17 +478,33 @@ async def caldav_action(text: str):
event_end = (event_time + timedelta(hours=1)).strftime("%Y%m%dT%H%M%S") # Assuming 1 hour duration

event = calendar.add_event(f"""
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:{event_name}
DTSTART:{event_start}
DTEND:{event_end}
END:VEVENT
END:VCALENDAR
""")
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:{event_name}
DTSTART:{event_start}
DTEND:{event_end}
END:VEVENT
END:VCALENDAR
""")
return f"Event '{event_name}' created successfully."

elif update_match:
event_name = update_match.group(2)
new_event_name = update_match.group(3)
event_time = datetime.strptime(f"{update_match.group(4)} {update_match.group(5)}", "%Y-%m-%d %H:%M")
event_start = event_time.strftime("%Y%m%dT%H%M%S")
event_end = (event_time + timedelta(hours=1)).strftime("%Y%m%dT%H%M%S") # Assuming 1 hour duration

events = calendar.search(start=datetime.now(), end=datetime.now() + timedelta(days=365), event=True, expand=True) # Search within the next year
for event in events:
if event_name.lower() in event.instance.vevent.summary.value.lower():
event.instance.vevent.summary.value = new_event_name
event.instance.vevent.dtstart.value = event_start
event.instance.vevent.dtend.value = event_end
event.save()
return f"Event '{event_name}' updated to '{new_event_name}' successfully."

elif delete_match:
event_name = delete_match.group(1)
events = calendar.search(start=datetime.now(), end=datetime.now() + timedelta(days=365), event=True, expand=True) # Search within the next year
Expand Down