summaryrefslogtreecommitdiff
path: root/note_tools/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'note_tools/__init__.py')
-rw-r--r--note_tools/__init__.py23
1 files changed, 22 insertions, 1 deletions
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
3from typing import Optional, Tuple 3from typing import Optional, Tuple
4 4
5class NoteBaseCommand(object): 5class NoteBaseCommand(object):
6 date = None 6 date = datetime.now()
7 7
8 def file_name(self): 8 def file_name(self):
9 return f"{self.date.strftime('%Y%m%d')}.md" 9 return f"{self.date.strftime('%Y%m%d')}.md"
@@ -35,3 +35,24 @@ class NoteBaseCommand(object):
35 if os.path.basename(folder_path).lower() == "notes": 35 if os.path.basename(folder_path).lower() == "notes":
36 return folder_path 36 return folder_path
37 return None 37 return None
38
39 def create_note(self, project_data, callback):
40 # Get the current date formatted as YYYYMMDD and YYYY-MM-DD
41 notes_path = self.get_notes_path(project_data)
42
43 if notes_path:
44 year, month = self.get_date_parts()
45 directory = os.path.join(notes_path, year, month)
46 os.makedirs(directory, exist_ok=True)
47 file_path = os.path.join(directory, self.file_name())
48
49 # Check if file already exists
50 if os.path.exists(file_path):
51 callback(False, f"The file '{self.file_name()}' already exists.")
52 else:
53 self.write_file_heading(file_path)
54 callback(True, None, file_path)
55
56 else:
57 callback(False, "No 'Notes' directory found in the project. Please add a 'Notes' folder.")
58