From f94fc6165ee09b970f6596f0d937c22555971f31 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Thu, 20 Feb 2025 18:12:10 -0500 Subject: Move create note logic into command base. --- note_tools/__init__.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'note_tools/__init__.py') diff --git a/note_tools/__init__.py b/note_tools/__init__.py index 8d6774d..0b4fcbd 100644 --- a/note_tools/__init__.py +++ b/note_tools/__init__.py @@ -3,7 +3,7 @@ import os from typing import Optional, Tuple class NoteBaseCommand(object): - date = None + date = datetime.now() def file_name(self): return f"{self.date.strftime('%Y%m%d')}.md" @@ -35,3 +35,24 @@ class NoteBaseCommand(object): if os.path.basename(folder_path).lower() == "notes": return folder_path return None + + def create_note(self, project_data, callback): + # Get the current date formatted as YYYYMMDD and YYYY-MM-DD + notes_path = self.get_notes_path(project_data) + + if notes_path: + year, month = self.get_date_parts() + directory = os.path.join(notes_path, year, month) + os.makedirs(directory, exist_ok=True) + file_path = os.path.join(directory, self.file_name()) + + # Check if file already exists + if os.path.exists(file_path): + callback(False, f"The file '{self.file_name()}' already exists.") + else: + self.write_file_heading(file_path) + callback(True, None, file_path) + + else: + callback(False, "No 'Notes' directory found in the project. Please add a 'Notes' folder.") + -- cgit v1.1