summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Berwaldt <zberwaldt@tutamail.com>2025-02-19 20:35:50 -0500
committerZach Berwaldt <zberwaldt@tutamail.com>2025-02-19 20:35:50 -0500
commit9cde3624920cb1ddd563b8addfcc65ccc79e080a (patch)
tree999bf10c56eec617af3c6eade7c0602878ae2be6
parentc6eb143b51b0c105b157e9d408d6e9fcfaa5abfc (diff)
Finish refactor
-rw-r--r--main.py14
-rw-r--r--note_tools/__init__.py5
-rw-r--r--note_tools/today.py (renamed from note_tools/commands.py)32
-rw-r--r--note_tools/tomorrow.py27
4 files changed, 42 insertions, 36 deletions
diff --git a/main.py b/main.py
index 67e7a35..816c721 100644
--- a/main.py
+++ b/main.py
@@ -1,9 +1,7 @@
1from .note_tools.commands import ( 1from .note_tools.today import NewNoteCommand
2 NewNoteCommand, 2from .note_tools.tomorrow import NewNoteForTomorrowCommand
3 NewNoteForTomorrowCommand
4)
5 3
6__all__= [ 4__all__ = [
7 "NewNoteCommand", 5 'NewNoteCommand',
8 "NewNoteForTomorrowCommand" 6 'NewNoteForTomorrowCommand'
9] 7] \ No newline at end of file
diff --git a/note_tools/__init__.py b/note_tools/__init__.py
index 69e6e67..8d6774d 100644
--- a/note_tools/__init__.py
+++ b/note_tools/__init__.py
@@ -1,7 +1,6 @@
1from datetime import datetime 1from datetime import datetime
2import os 2import os
3from typing import List, Optional, Tuple 3from typing import Optional, Tuple
4
5 4
6class NoteBaseCommand(object): 5class NoteBaseCommand(object):
7 date = None 6 date = None
@@ -16,7 +15,7 @@ class NoteBaseCommand(object):
16 return datetime.now() 15 return datetime.now()
17 16
18 def get_date_parts(self) -> Tuple[str]: 17 def get_date_parts(self) -> Tuple[str]:
19 return (self.date.strftime('%Y'), self.date.strftime('%m'), self.date.strftime('%d')) 18 return (self.date.strftime('%Y'), self.date.strftime('%m'))
20 19
21 def write_file_heading(self, file_path): 20 def write_file_heading(self, file_path):
22 date_yyyymmdd = self.date.strftime('%Y-%m-%d') 21 date_yyyymmdd = self.date.strftime('%Y-%m-%d')
diff --git a/note_tools/commands.py b/note_tools/today.py
index 97778ba..20f2e53 100644
--- a/note_tools/commands.py
+++ b/note_tools/today.py
@@ -1,29 +1,9 @@
1from . import NoteBaseCommand 1from . import NoteBaseCommand
2import sublime_plugin
3import datetime
4import os 2import os
5from typing import List, Optional, Tuple 3import sublime
6 4import sublime_plugin
7class NewNoteForTomorrowCommand(NoteBaseCommand, sublime_plugin.WindowCommand): 5from pathlib import Path
8 def run(self): 6from typing import List, Optional
9 self.date = self.get_date() + timedelta(days=1)
10
11 notes_path = self.get_notes_path(self.window.project_data())
12
13 if notes_path:
14 year, month, day = self.get_date_parts()
15 directory = os.path.join(notes_path, year, month)
16 os.makedirs(directory, exist_ok=True)
17 file_path = os.path.join(directory, self.file_name())
18
19 # Check if file already exists
20 if os.path.exists(file_path):
21 sublime.message_dialog(f"The file '{self.file_name()}' already exists.")
22 else:
23 self.write_file_heading(file_path)
24
25 else:
26 sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.")
27 7
28class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand): 8class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand):
29 def run(self): 9 def run(self):
@@ -32,10 +12,12 @@ class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand):
32 notes_path = self.get_notes_path(self.window.project_data()) 12 notes_path = self.get_notes_path(self.window.project_data())
33 13
34 if notes_path: 14 if notes_path:
35 year, month, day = self.get_date_parts() 15 year, month = self.get_date_parts()
36 directory = os.path.join(notes_path, year, month) 16 directory = os.path.join(notes_path, year, month)
17 print("directory: ", directory)
37 os.makedirs(directory, exist_ok=True) 18 os.makedirs(directory, exist_ok=True)
38 file_path = os.path.join(directory, self.file_name()) 19 file_path = os.path.join(directory, self.file_name())
20 print('path: ', file_path)
39 21
40 # Check if file already exists 22 # Check if file already exists
41 if os.path.exists(file_path): 23 if os.path.exists(file_path):
diff --git a/note_tools/tomorrow.py b/note_tools/tomorrow.py
new file mode 100644
index 0000000..2198a3b
--- /dev/null
+++ b/note_tools/tomorrow.py
@@ -0,0 +1,27 @@
1from . import NoteBaseCommand
2import os
3from datetime import timedelta
4import sublime
5import sublime_plugin
6
7class NewNoteForTomorrowCommand(NoteBaseCommand, sublime_plugin.WindowCommand):
8 def run(self):
9 self.date = self.get_date() + timedelta(days=1)
10
11 notes_path = self.get_notes_path(self.window.project_data())
12
13 if notes_path:
14 year, month = self.get_date_parts()
15 directory = os.path.join(notes_path, year, month)
16 os.makedirs(directory, exist_ok=True)
17 file_path = os.path.join(directory, self.file_name())
18
19 # Check if file already exists
20 if os.path.exists(file_path):
21 sublime.message_dialog(f"The file '{self.file_name()}' already exists.")
22 else:
23 self.write_file_heading(file_path)
24
25 else:
26 sublime.message_dialog("No 'Notes' directory found in the project. Please add a 'Notes' folder.")
27