mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-02 06:56:12 +02:00
Create separate DayOneEntry class to hold DayOne's extra data
This commit is contained in:
parent
15ef9749ae
commit
eca35b106b
2 changed files with 28 additions and 4 deletions
|
@ -45,7 +45,7 @@ class DayOne(Journal.Journal):
|
|||
raw = dict_entry['Entry Text']
|
||||
sep = re.search("\n|[\?!.]+ +\n?", raw)
|
||||
title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
|
||||
entry = Entry.Entry(self, date, title, body, starred=dict_entry["Starred"])
|
||||
entry = Entry.DayOneEntry(self, date, title, body, starred=dict_entry["Starred"])
|
||||
entry.uuid = dict_entry["UUID"]
|
||||
entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])]
|
||||
self.entries.append(entry)
|
||||
|
@ -99,7 +99,7 @@ class DayOne(Journal.Journal):
|
|||
if m:
|
||||
if current_entry:
|
||||
entries.append(current_entry)
|
||||
current_entry = Entry.Entry(self)
|
||||
current_entry = Entry.DayOneEntry(self)
|
||||
current_entry.modified = False
|
||||
current_entry.uuid = m.group(1).lower()
|
||||
else:
|
||||
|
@ -111,8 +111,10 @@ class DayOne(Journal.Journal):
|
|||
current_entry.title = line[date_length + 1:]
|
||||
current_entry.date = new_date
|
||||
except ValueError:
|
||||
# strptime failed to parse a date, so assume this line is part of the journal
|
||||
# entry
|
||||
if current_entry:
|
||||
current_entry.body += line + "\n"
|
||||
current_entry.body += line + "\n"
|
||||
|
||||
# Append last entry
|
||||
if current_entry:
|
||||
|
|
|
@ -7,7 +7,7 @@ import textwrap
|
|||
from datetime import datetime
|
||||
|
||||
|
||||
class Entry:
|
||||
class Entry(object):
|
||||
def __init__(self, journal, date=None, title="", body="", starred=False):
|
||||
self.journal = journal # Reference to journal mainly to access it's config
|
||||
self.date = date or datetime.now()
|
||||
|
@ -109,3 +109,25 @@ class Entry:
|
|||
body=body,
|
||||
space=space
|
||||
)
|
||||
|
||||
|
||||
class DayOneEntry(Entry):
|
||||
def __init__(self, journal, *args, **kwargs):
|
||||
|
||||
# Make sure all our args are converted to kwargs before calling super
|
||||
try:
|
||||
kwargs['date'] = args[0]
|
||||
kwargs['title'] = args[1]
|
||||
kwargs['body'] = args[2]
|
||||
kwargs['starred'] = args[3]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# store extra day one data inside the entry. This should be a dict containing all the data that
|
||||
# day one stores but which is not relevant to jrnl
|
||||
self.extra_data = None
|
||||
|
||||
if kwargs.get('extra_data'):
|
||||
self.extra_data = kwargs.pop('extra_data')
|
||||
|
||||
super(DayOneEntry, self).__init__(journal, **kwargs)
|
Loading…
Add table
Add a link
Reference in a new issue