mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-02 23:06:13 +02:00
Ignore all files in folder journal except year/month/day.txt
This commit is contained in:
parent
ba3622f08f
commit
c5236fee7c
1 changed files with 22 additions and 4 deletions
|
@ -14,15 +14,33 @@ if TYPE_CHECKING:
|
||||||
from jrnl.journals import Entry
|
from jrnl.journals import Entry
|
||||||
|
|
||||||
|
|
||||||
def get_files(journal_config: str) -> list[str]:
|
def get_files(journal_path: str) -> list[str]:
|
||||||
"""Searches through sub directories starting with journal_config and find all text files"""
|
"""Searches through sub directories starting with journal_path and find all text files that look like entries"""
|
||||||
filenames = []
|
filenames = []
|
||||||
for root, dirnames, f in os.walk(journal_config):
|
for dirpath, dirnames, f in os.walk(journal_path):
|
||||||
for filename in fnmatch.filter(f, "*.txt"):
|
for filename in fnmatch.filter(f, "*.txt"):
|
||||||
filenames.append(os.path.join(root, filename))
|
if _should_file_be_opened(journal_path, dirpath, filename):
|
||||||
|
filenames.append(os.path.join(dirpath, filename))
|
||||||
return filenames
|
return filenames
|
||||||
|
|
||||||
|
|
||||||
|
def _should_file_be_opened(journal_path: str, dirpath: str, filename: str) -> bool:
|
||||||
|
"""Checks whether a file should be opened based on its name and location in the folder journal structure"""
|
||||||
|
if journal_path[-1] in ["\\", "/"]:
|
||||||
|
journal_path = journal_path[:-1] # no trailing slash
|
||||||
|
|
||||||
|
filename_without_extension = os.path.splitext(filename)[0]
|
||||||
|
|
||||||
|
return (
|
||||||
|
dirpath != journal_path # don't read any files in top level
|
||||||
|
and os.path.dirname(dirpath) != journal_path # no files in year
|
||||||
|
and os.path.basename(dirpath).isdigit() # month dir is numbers
|
||||||
|
and len(os.path.basename(dirpath)) <= 2 # month dir is 1-2 digits
|
||||||
|
and filename_without_extension.isdigit() # day of the month
|
||||||
|
and len(filename_without_extension) <= 2 # day of the month
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Folder(Journal):
|
class Folder(Journal):
|
||||||
"""A Journal handling multiple files in a folder"""
|
"""A Journal handling multiple files in a folder"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue