mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 21:46:13 +02:00
Starring entries and looking at the stars
This commit is contained in:
parent
9356fb13fa
commit
82336ffe75
3 changed files with 33 additions and 10 deletions
|
@ -133,12 +133,20 @@ class Journal(object):
|
|||
for line in journal.splitlines():
|
||||
try:
|
||||
# try to parse line as date => new entry begins
|
||||
line = line.strip()
|
||||
new_date = datetime.strptime(line[:date_length], self.config['timeformat'])
|
||||
|
||||
# parsing successfull => save old entry and create new one
|
||||
if new_date and current_entry:
|
||||
entries.append(current_entry)
|
||||
current_entry = Entry.Entry(self, date=new_date, title=line[date_length+1:])
|
||||
|
||||
if line.endswith("*"):
|
||||
starred = True
|
||||
line = line[:-1]
|
||||
else:
|
||||
starred = False
|
||||
|
||||
current_entry = Entry.Entry(self, date=new_date, title=line[date_length+1:], starred=starred)
|
||||
except ValueError:
|
||||
# Happens when we can't parse the start of the line as an date.
|
||||
# In this case, just append line to our body.
|
||||
|
@ -196,7 +204,7 @@ class Journal(object):
|
|||
if n:
|
||||
self.entries = self.entries[-n:]
|
||||
|
||||
def filter(self, tags=[], start_date=None, end_date=None, strict=False, short=False):
|
||||
def filter(self, tags=[], start_date=None, end_date=None, starred=False, strict=False, short=False):
|
||||
"""Removes all entries from the journal that don't match the filter.
|
||||
|
||||
tags is a list of tags, each being a string that starts with one of the
|
||||
|
@ -204,6 +212,8 @@ class Journal(object):
|
|||
|
||||
start_date and end_date define a timespan by which to filter.
|
||||
|
||||
starred limits journal to starred entries
|
||||
|
||||
If strict is True, all tags must be present in an entry. If false, the
|
||||
entry is kept if any tag is present."""
|
||||
self.search_tags = set([tag.lower() for tag in tags])
|
||||
|
@ -214,6 +224,7 @@ class Journal(object):
|
|||
result = [
|
||||
entry for entry in self.entries
|
||||
if (not tags or tagged(entry.tags))
|
||||
and (not starred or entry.starred)
|
||||
and (not start_date or entry.date > start_date)
|
||||
and (not end_date or entry.date < end_date)
|
||||
]
|
||||
|
@ -264,7 +275,7 @@ class Journal(object):
|
|||
If a date is given, it will parse and use this, otherwise scan for a date in the input first."""
|
||||
|
||||
raw = raw.replace('\\n ', '\n').replace('\\n', '\n')
|
||||
|
||||
starred = False
|
||||
# Split raw text into title and body
|
||||
title_end = len(raw)
|
||||
for separator in ["\n", ". ", "? ", "! "]:
|
||||
|
@ -273,15 +284,22 @@ class Journal(object):
|
|||
title_end = sep_pos
|
||||
title = raw[:title_end+1]
|
||||
body = raw[title_end+1:].strip()
|
||||
starred = False
|
||||
if not date:
|
||||
if title.find(":") > 0:
|
||||
starred = "*" in title[:title.find(":")]
|
||||
date = self.parse_date(title[:title.find(":")])
|
||||
if date: # Parsed successfully, strip that from the raw text
|
||||
if date or starred: # Parsed successfully, strip that from the raw text
|
||||
title = title[title.find(":")+1:].strip()
|
||||
elif title.strip().startswith("*"):
|
||||
starred = True
|
||||
title = title[1:].strip()
|
||||
elif title.strip().endswith("*"):
|
||||
starred = True
|
||||
title = title[:-1].strip()
|
||||
if not date: # Still nothing? Meh, just live in the moment.
|
||||
date = self.parse_date("now")
|
||||
|
||||
entry = Entry.Entry(self, date, title, body)
|
||||
entry = Entry.Entry(self, date, title, body, starred=starred)
|
||||
self.entries.append(entry)
|
||||
if sort:
|
||||
self.sort()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue