add task reminder

This commit is contained in:
2024-06-17 21:56:53 +02:00
parent 2c48fd997e
commit 465a4c2f03
12 changed files with 60 additions and 0 deletions

View File

@@ -4,7 +4,40 @@ from my_project_name.chat_functions import react_to_event, send_text_to_room
from my_project_name.config import Config from my_project_name.config import Config
from my_project_name.storage import Storage from my_project_name.storage import Storage
from my_project_name.caldav_handler import CaldavHandler from my_project_name.caldav_handler import CaldavHandler
import json
import requests
def weekly_reminder():
api_url = "https://tasklist.malobeo.org/api/next"
response = requests.get(api_url)
if response.status_code != 200:
return "Error requesting " + api_url + " Status Code: " + str(response.status_code)
data = response.json()
message = "# Weekly Task Reminder\n"
for task in data:
message += "- {}: **{}**\n".format(task["Name"], task["Value"])
message += "\n*Write* ```!c tasks``` *to get details about the tasks*"
return message
def task_help():
api_url = "https://tasklist.malobeo.org/api/next"
response = requests.get(api_url)
if response.status_code != 200:
return "Error requesting " + api_url + " Status Code: " + str(response.status_code)
data = response.json()
message = "# Tasks for this week\n"
for task in data:
message += "- {} ({}): {}\n".format(task["Name"], task["Value"], task["Description"])
return message
class Command: class Command:
def __init__( def __init__(
@@ -53,6 +86,8 @@ class Command:
await self._show_week() await self._show_week()
elif self.command.startswith("month"): elif self.command.startswith("month"):
await self._show_month() await self._show_month()
elif self.command.startswith("tasks"):
await self._show_tasks()
#else: #else:
# await self._unknown_command() # await self._unknown_command()
@@ -73,6 +108,10 @@ class Command:
response = handler.print_month() response = handler.print_month()
await send_text_to_room(self.client, self.room.room_id, response, markdown_convert=True) await send_text_to_room(self.client, self.room.room_id, response, markdown_convert=True)
async def _show_tasks(self):
response = task_help()
await send_text_to_room(self.client, self.room.room_id, response, markdown_convert=True)
async def _echo(self): async def _echo(self):
"""Echo back the command's arguments""" """Echo back the command's arguments"""
response = " ".join(self.args) response = " ".join(self.args)

View File

@@ -4,6 +4,7 @@ import logging
import threading import threading
import sys import sys
from time import sleep from time import sleep
import datetime
from aiohttp import ClientConnectionError, ServerDisconnectedError from aiohttp import ClientConnectionError, ServerDisconnectedError
from nio import ( from nio import (
@@ -28,6 +29,22 @@ logger = logging.getLogger(__name__)
from datetime import datetime, time from datetime import datetime, time
def weekly_task_reminder():
api_url = "https://tasklist.malobeo.org/api/next"
response = requests.get(api_url)
if response.status_code != 200:
return "Error requesting " + api_url + " Status Code: " + str(response.status_code)
data = response.json()
message = "# Weekly Task Reminder\n"
for task in data:
message += "- {}: **{}**\n".format(task["Name"], task["Value"])
message += "\n*Write* ```!c tasks``` *to get details about the tasks*"
return message
def is_time_between(begin_time, end_time, check_time=None): def is_time_between(begin_time, end_time, check_time=None):
# If check time is not given, default to current UTC time # If check time is not given, default to current UTC time
check_time = check_time or datetime.utcnow().time() check_time = check_time or datetime.utcnow().time()
@@ -46,6 +63,10 @@ async def foo(client):
messages = handler.send_reminders() messages = handler.send_reminders()
for message in messages: for message in messages:
await send_text_to_room(client, "!aRFGSGKGeaBxiEfDMC:matrix.org", message) await send_text_to_room(client, "!aRFGSGKGeaBxiEfDMC:matrix.org", message)
if datetime.datetime.today().weekday() == 1: #check if its tuesday
await send_text_to_room(client, "!aRFGSGKGeaBxiEfDMC:matrix.org", weekly_task_reminder())
ShouldSendReminder = False ShouldSendReminder = False
else: else:
ShouldSendReminder = True ShouldSendReminder = True