add task reminder
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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.storage import Storage
|
||||
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:
|
||||
def __init__(
|
||||
@@ -53,6 +86,8 @@ class Command:
|
||||
await self._show_week()
|
||||
elif self.command.startswith("month"):
|
||||
await self._show_month()
|
||||
elif self.command.startswith("tasks"):
|
||||
await self._show_tasks()
|
||||
#else:
|
||||
# await self._unknown_command()
|
||||
|
||||
@@ -73,6 +108,10 @@ class Command:
|
||||
response = handler.print_month()
|
||||
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):
|
||||
"""Echo back the command's arguments"""
|
||||
response = " ".join(self.args)
|
||||
|
||||
@@ -4,6 +4,7 @@ import logging
|
||||
import threading
|
||||
import sys
|
||||
from time import sleep
|
||||
import datetime
|
||||
|
||||
from aiohttp import ClientConnectionError, ServerDisconnectedError
|
||||
from nio import (
|
||||
@@ -28,6 +29,22 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
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):
|
||||
# If check time is not given, default to current UTC time
|
||||
check_time = check_time or datetime.utcnow().time()
|
||||
@@ -46,6 +63,10 @@ async def foo(client):
|
||||
messages = handler.send_reminders()
|
||||
for message in messages:
|
||||
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
|
||||
else:
|
||||
ShouldSendReminder = True
|
||||
|
||||
Reference in New Issue
Block a user