diff options
| author | Zach Berwaldt <zberwaldt@tutamail.com> | 2025-02-19 20:35:50 -0500 |
|---|---|---|
| committer | Zach Berwaldt <zberwaldt@tutamail.com> | 2025-02-19 20:35:50 -0500 |
| commit | 9cde3624920cb1ddd563b8addfcc65ccc79e080a (patch) | |
| tree | 999bf10c56eec617af3c6eade7c0602878ae2be6 | |
| parent | c6eb143b51b0c105b157e9d408d6e9fcfaa5abfc (diff) | |
Finish refactor
| -rw-r--r-- | main.py | 14 | ||||
| -rw-r--r-- | note_tools/__init__.py | 5 | ||||
| -rw-r--r-- | note_tools/today.py (renamed from note_tools/commands.py) | 32 | ||||
| -rw-r--r-- | note_tools/tomorrow.py | 27 |
4 files changed, 42 insertions, 36 deletions
| @@ -1,9 +1,7 @@ | |||
| 1 | from .note_tools.commands import ( | 1 | from .note_tools.today import NewNoteCommand |
| 2 | NewNoteCommand, | 2 | from .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 @@ | |||
| 1 | from datetime import datetime | 1 | from datetime import datetime |
| 2 | import os | 2 | import os |
| 3 | from typing import List, Optional, Tuple | 3 | from typing import Optional, Tuple |
| 4 | |||
| 5 | 4 | ||
| 6 | class NoteBaseCommand(object): | 5 | class 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 @@ | |||
| 1 | from . import NoteBaseCommand | 1 | from . import NoteBaseCommand |
| 2 | import sublime_plugin | ||
| 3 | import datetime | ||
| 4 | import os | 2 | import os |
| 5 | from typing import List, Optional, Tuple | 3 | import sublime |
| 6 | 4 | import sublime_plugin | |
| 7 | class NewNoteForTomorrowCommand(NoteBaseCommand, sublime_plugin.WindowCommand): | 5 | from pathlib import Path |
| 8 | def run(self): | 6 | from 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 | ||
| 28 | class NewNoteCommand(NoteBaseCommand, sublime_plugin.WindowCommand): | 8 | class 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 @@ | |||
| 1 | from . import NoteBaseCommand | ||
| 2 | import os | ||
| 3 | from datetime import timedelta | ||
| 4 | import sublime | ||
| 5 | import sublime_plugin | ||
| 6 | |||
| 7 | class 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 | |||
