From ca6b16a5a12d671f0e7c62dae174f01abd03879d Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Fri, 20 Dec 2013 21:11:47 +0100 Subject: [PATCH] Cleaner parsing --- jrnl/Journal.py | 21 +++++++-------------- jrnl/cli.py | 3 +-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 8a14d008..52ab7676 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -285,13 +285,8 @@ class Journal(object): 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", ". ", "? ", "! "]: - sep_pos = raw.find(separator) - if 1 < sep_pos < title_end: - title_end = sep_pos - title = raw[:title_end+1] - body = raw[title_end+1:].strip() + sep = re.search("[\n!?.]+", raw) + title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "") starred = False if not date: if title.find(":") > 0: @@ -338,15 +333,13 @@ class DayOne(Journal): timezone = pytz.timezone(util.get_local_timezone()) date = dict_entry['Creation Date'] date = date + timezone.utcoffset(date) - entry = self.new_entry(raw=dict_entry['Entry Text'], date=date, sort=False) - entry.starred = dict_entry["Starred"] + raw = dict_entry['Entry Text'] + sep = re.search("[\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.uuid = dict_entry["UUID"] entry.tags = dict_entry.get("Tags", []) - # We're using new_entry to create the Entry object, which adds the entry - # to self.entries already. However, in the original Journal.__init__, this - # method is expected to return a list of newly created entries, which is why - # we're returning the obvious. - return self.entries + self.entries.append(entry) def write(self): """Writes only the entries that have been modified into plist files.""" diff --git a/jrnl/cli.py b/jrnl/cli.py index fb5a03ae..529b6f0b 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -148,11 +148,10 @@ def run(manual_args=None): else: journal = Journal.Journal(journal_name, **config) + # How to quit writing? if "win32" in sys.platform: - # for Windows systems _exit_multiline_code = "on a blank line, press Ctrl+Z and then Enter" else: - # for *nix systems (and others?) _exit_multiline_code = "press Ctrl+D" if mode_compose and not args.text: