From 00fe2fb442135ec48073c2da2a4dc1672e36c000 Mon Sep 17 00:00:00 2001 From: josiah Date: Sat, 14 Aug 2021 23:01:04 -0500 Subject: [PATCH] Add deadline and date calcs. --- molly/bot_commands.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/molly/bot_commands.py b/molly/bot_commands.py index 90d1859..6fcefbd 100644 --- a/molly/bot_commands.py +++ b/molly/bot_commands.py @@ -1,5 +1,8 @@ from nio import AsyncClient, MatrixRoom, RoomMessageText +import datetime +import calendar + from molly.chat_functions import react_to_event, send_text_to_room from molly.config import Config from molly.storage import Storage @@ -91,12 +94,13 @@ class Command: async def _new_org_todo(self): """Given a plaintext string, return org-formatted todo line.""" + due_today = get_orgmode_deadline_string() formatted_string = " ".join(self.args) - new_string = f"* TODO {formatted_string} \n" + new_string = f"* TODO {formatted_string}" await send_text_to_room(self.client, self.room.room_id, f"creating new todo with {new_string}") print(dir(self.config)) with open(self.config.orgmode_refile_path, "a") as orgfile: - orgfile.write(new_string) + orgfile.write(f"{new_string}\n{due_today}\n") # return new_string async def _unknown_command(self): @@ -105,3 +109,14 @@ class Command: self.room.room_id, f"Unknown command '{self.command}'. Try the 'help' command for more information.", ) + + +def get_orgmode_deadline_string(): + """Return an orgmode formatted todo deadline string, for example: + DEADLINE: <2021-08-14 Sat> + """ + date = datetime.date.today().isoformat() + weekday = calendar.day_name[datetime.date.today().weekday()] + deadline_string = f"DEADLINE: <{date} {weekday[0:3]}>" + + return deadline_string