mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
Introduce -reminisce, -month, -day, and -year
This commit is contained in:
parent
c155bafa84
commit
f19ae0be86
3 changed files with 47 additions and 0 deletions
|
@ -189,6 +189,9 @@ class Journal:
|
||||||
def filter(
|
def filter(
|
||||||
self,
|
self,
|
||||||
tags=[],
|
tags=[],
|
||||||
|
month=None,
|
||||||
|
day=None,
|
||||||
|
year=None,
|
||||||
start_date=None,
|
start_date=None,
|
||||||
end_date=None,
|
end_date=None,
|
||||||
starred=False,
|
starred=False,
|
||||||
|
@ -220,11 +223,18 @@ class Journal:
|
||||||
if contains:
|
if contains:
|
||||||
contains_lower = contains.casefold()
|
contains_lower = contains.casefold()
|
||||||
|
|
||||||
|
# Create datetime object for comparison below
|
||||||
|
# this approach allows different month formats
|
||||||
|
compare_d = time.parse(f"{month or 1}/{day or 1}/{year or 1}")
|
||||||
|
|
||||||
result = [
|
result = [
|
||||||
entry
|
entry
|
||||||
for entry in self.entries
|
for entry in self.entries
|
||||||
if (not tags or tagged(entry.tags))
|
if (not tags or tagged(entry.tags))
|
||||||
and (not starred or entry.starred)
|
and (not starred or entry.starred)
|
||||||
|
and (not month or entry.date.month == compare_d.month)
|
||||||
|
and (not day or entry.date.day == compare_d.day)
|
||||||
|
and (not year or entry.date.year == compare_d.year)
|
||||||
and (not start_date or entry.date >= start_date)
|
and (not start_date or entry.date >= start_date)
|
||||||
and (not end_date or entry.date <= end_date)
|
and (not end_date or entry.date <= end_date)
|
||||||
and (not exclude or not excluded(entry.tags))
|
and (not exclude or not excluded(entry.tags))
|
||||||
|
|
24
jrnl/args.py
24
jrnl/args.py
|
@ -176,6 +176,30 @@ def parse_args(args=[]):
|
||||||
reading.add_argument(
|
reading.add_argument(
|
||||||
"-on", dest="on_date", metavar="DATE", help="Show entries on this date"
|
"-on", dest="on_date", metavar="DATE", help="Show entries on this date"
|
||||||
)
|
)
|
||||||
|
reading.add_argument(
|
||||||
|
"-reminisce",
|
||||||
|
dest="reminisce",
|
||||||
|
action="store_true",
|
||||||
|
help="Show entries of today in previous years",
|
||||||
|
)
|
||||||
|
reading.add_argument(
|
||||||
|
"-month",
|
||||||
|
dest="month",
|
||||||
|
metavar="DATE",
|
||||||
|
help="Show entries on this month of any year",
|
||||||
|
)
|
||||||
|
reading.add_argument(
|
||||||
|
"-day",
|
||||||
|
dest="day",
|
||||||
|
metavar="DATE",
|
||||||
|
help="Show entries on this day of any month",
|
||||||
|
)
|
||||||
|
reading.add_argument(
|
||||||
|
"-year",
|
||||||
|
dest="year",
|
||||||
|
metavar="DATE",
|
||||||
|
help="Show entries on this year",
|
||||||
|
)
|
||||||
reading.add_argument(
|
reading.add_argument(
|
||||||
"-from",
|
"-from",
|
||||||
dest="start_date",
|
dest="start_date",
|
||||||
|
|
13
jrnl/jrnl.py
13
jrnl/jrnl.py
|
@ -15,6 +15,7 @@ from .config import get_config_path
|
||||||
from .editor import get_text_from_editor
|
from .editor import get_text_from_editor
|
||||||
from .editor import get_text_from_stdin
|
from .editor import get_text_from_stdin
|
||||||
from .exception import UserAbort
|
from .exception import UserAbort
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
|
@ -77,6 +78,10 @@ def _is_write_mode(args, config, **kwargs):
|
||||||
args.edit,
|
args.edit,
|
||||||
args.export,
|
args.export,
|
||||||
args.end_date,
|
args.end_date,
|
||||||
|
args.reminisce,
|
||||||
|
args.month,
|
||||||
|
args.day,
|
||||||
|
args.year,
|
||||||
args.limit,
|
args.limit,
|
||||||
args.on_date,
|
args.on_date,
|
||||||
args.short,
|
args.short,
|
||||||
|
@ -206,8 +211,16 @@ def _search_journal(args, journal, **kwargs):
|
||||||
if args.on_date:
|
if args.on_date:
|
||||||
args.start_date = args.end_date = args.on_date
|
args.start_date = args.end_date = args.on_date
|
||||||
|
|
||||||
|
if args.reminisce:
|
||||||
|
today = datetime.today()
|
||||||
|
args.day = today.day
|
||||||
|
args.month = today.month
|
||||||
|
|
||||||
journal.filter(
|
journal.filter(
|
||||||
tags=args.text,
|
tags=args.text,
|
||||||
|
month=args.month,
|
||||||
|
day=args.day,
|
||||||
|
year=args.year,
|
||||||
start_date=args.start_date,
|
start_date=args.start_date,
|
||||||
end_date=args.end_date,
|
end_date=args.end_date,
|
||||||
strict=args.strict,
|
strict=args.strict,
|
||||||
|
|
Loading…
Add table
Reference in a new issue