diff options
Diffstat (limited to 'note_tools/__init__.py')
-rw-r--r-- | note_tools/__init__.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/note_tools/__init__.py b/note_tools/__init__.py index e69de29..8d6774d 100644 --- a/note_tools/__init__.py +++ b/note_tools/__init__.py | |||
@@ -0,0 +1,37 @@ | |||
1 | from datetime import datetime | ||
2 | import os | ||
3 | from typing import Optional, Tuple | ||
4 | |||
5 | class NoteBaseCommand(object): | ||
6 | date = None | ||
7 | |||
8 | def file_name(self): | ||
9 | return f"{self.date.strftime('%Y%m%d')}.md" | ||
10 | |||
11 | def get_formatted_dates(self) -> Tuple[str, str]: | ||
12 | return (self.date.strftime("%Y%m%d"), self.date.strftime("%Y-%m-%d")) | ||
13 | |||
14 | def get_date(self) -> datetime: | ||
15 | return datetime.now() | ||
16 | |||
17 | def get_date_parts(self) -> Tuple[str]: | ||
18 | return (self.date.strftime('%Y'), self.date.strftime('%m')) | ||
19 | |||
20 | def write_file_heading(self, file_path): | ||
21 | date_yyyymmdd = self.date.strftime('%Y-%m-%d') | ||
22 | underline = '=' * len(date_yyyymmdd) | ||
23 | with open(file_path, 'w') as file: | ||
24 | file.write(f"{date_yyyymmdd}\n{underline}\n\n\n") | ||
25 | |||
26 | def parse_file_date (self, file_name: str) -> Tuple[str, str]: | ||
27 | year = file_name[:4] | ||
28 | month = file_name[4:6] | ||
29 | return year, month | ||
30 | |||
31 | def get_notes_path(self, project_data) -> Optional[str]: | ||
32 | if project_data and 'folders' in project_data: | ||
33 | for folder in project_data['folders']: | ||
34 | folder_path = folder['path'] | ||
35 | if os.path.basename(folder_path).lower() == "notes": | ||
36 | return folder_path | ||
37 | return None | ||