From 6da4e44e39807d778ecf38cae89a278aaad5069b Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 13:14:16 -0400 Subject: [PATCH 1/6] Warns if using --edit without editor Closes #151 --- jrnl/cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jrnl/cli.py b/jrnl/cli.py index 5830aebf..417398a4 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -233,6 +233,9 @@ def run(manual_args=None): install.save_config(original_config, config_path=CONFIG_PATH) elif args.edit: + if not config['editor']: + util.prompt(u"[You need to specify an editor in {0} to use the --edit function.]".format(CONFIG_PATH)) + sys.exit(1) other_entries = [e for e in old_entries if e not in journal.entries] # Edit old_num_entries = len(journal) From 414acf2ae61669a8ba3f3b42265f4d3b1c3225fc Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 14:25:56 -0400 Subject: [PATCH 2/6] Assumes no DST in case of ambiguous dates Fixes #153 --- jrnl/Journal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 3a7f00f5..fffa8781 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -338,7 +338,7 @@ class DayOne(Journal): except (KeyError, pytz.exceptions.UnknownTimeZoneError): timezone = tzlocal.get_localzone() date = dict_entry['Creation Date'] - date = date + timezone.utcoffset(date) + date = date + timezone.utcoffset(date, is_dst=False) raw = dict_entry['Entry Text'] sep = re.search("[\n!?.]+", raw) title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "") From 00f122ed1ac60064d917f6b62272cb2ac0caf07b Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 14:26:02 -0400 Subject: [PATCH 3/6] Tests for #153 --- features/data/configs/bug153.json | 14 +++++ .../B40EE704E15846DE8D45C44118A4D511.doentry | 56 +++++++++++++++++++ features/regression.feature | 10 ++++ 3 files changed, 80 insertions(+) create mode 100644 features/data/configs/bug153.json create mode 100644 features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D511.doentry diff --git a/features/data/configs/bug153.json b/features/data/configs/bug153.json new file mode 100644 index 00000000..ad617928 --- /dev/null +++ b/features/data/configs/bug153.json @@ -0,0 +1,14 @@ +{ + "default_hour": 9, + "timeformat": "%Y-%m-%d %H:%M", + "linewrap": 80, + "encrypt": false, + "editor": "", + "default_minute": 0, + "highlight": true, + "password": "", + "journals": { + "default": "features/journals/bug153.dayone" + }, + "tagsymbols": "@" +} diff --git a/features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D511.doentry b/features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D511.doentry new file mode 100644 index 00000000..745a08df --- /dev/null +++ b/features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D511.doentry @@ -0,0 +1,56 @@ + + + + + Creation Date + 2013-10-27T02:27:27Z + Creator + + Device Agent + iPhone/iPhone3,1 + Generation Date + 2013-10-27T07:02:27Z + Host Name + omrt104001 + OS Agent + iOS/7.0.3 + Software Agent + Day One (iOS)/1.11.4 + + Entry Text + Some text. + Location + + Administrative Area + Östergötlands län + Country + Sverige + Latitude + 58.383400000000000 + Locality + City + Longitude + 15.577170000000000 + Place Name + Street + + Starred + + Time Zone + Europe/Stockholm + UUID + B40EE704E15846DE8D45C44118A4D511 + Weather + + Celsius + 12 + Description + Clear + Fahrenheit + 54 + IconName + sunnyn.png + + + diff --git a/features/regression.feature b/features/regression.feature index af2c01f8..029c257c 100644 --- a/features/regression.feature +++ b/features/regression.feature @@ -20,3 +20,13 @@ Feature: Zapped bugs should stay dead. When we run "jrnl 2013-11-30 15:42: Project Started." Then we should see the message "Entry added" and the journal should contain "2013-11-30 15:42 Project Started." + + Scenario: Loading entry with ambiguous time stamp + #https://github.com/maebert/jrnl/issues/153 + Given we use the config "bug153.json" + When we run "jrnl -1" + Then we should get no error + and the output should be + """ + 2013-10-27 03:27 Some text. + """ From e887d6169907daa13eb42a424fe031cf90a5b176 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 14:28:21 -0400 Subject: [PATCH 4/6] version bump --- CHANGELOG.md | 1 + jrnl/__init__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3887a3d..3aff2011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog ### 1.7 (December 22, 2013) +* __1.7.20__ Minor fixes when parsing DayOne journals * __1.7.19__ Creates full path to journal during installation if it doesn't exist yet * __1.7.18__ Small update to parsing regex * __1.7.17__ Fixes writing new lines between entries diff --git a/jrnl/__init__.py b/jrnl/__init__.py index abed03dd..7bb44098 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line. from __future__ import absolute_import __title__ = 'jrnl' -__version__ = '1.7.19' +__version__ = '1.7.20' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 - 2014 Manuel Ebert' From 7dfe379982dcd3e36ad6d171141014c72458138b Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 14:34:39 -0400 Subject: [PATCH 5/6] Ignore unreadably DayOne entries --- jrnl/Journal.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index fffa8781..7c83b2af 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -24,6 +24,7 @@ import plistlib import pytz import uuid import tzlocal +from xml.parsers.expat import ExpatError class Journal(object): @@ -332,20 +333,24 @@ class DayOne(Journal): self.entries = [] for filename in filenames: with open(filename, 'rb') as plist_entry: - dict_entry = plistlib.readPlist(plist_entry) try: - timezone = pytz.timezone(dict_entry['Time Zone']) - except (KeyError, pytz.exceptions.UnknownTimeZoneError): - timezone = tzlocal.get_localzone() - date = dict_entry['Creation Date'] - date = date + timezone.utcoffset(date, is_dst=False) - 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 = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])] - self.entries.append(entry) + dict_entry = plistlib.readPlist(plist_entry) + except ExpatError: + pass + else: + try: + timezone = pytz.timezone(dict_entry['Time Zone']) + except (KeyError, pytz.exceptions.UnknownTimeZoneError): + timezone = tzlocal.get_localzone() + date = dict_entry['Creation Date'] + date = date + timezone.utcoffset(date, is_dst=False) + 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 = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])] + self.entries.append(entry) self.sort() def write(self): From 91de932568c1a706c0afabade0183921dae56c6c Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 14:35:03 -0400 Subject: [PATCH 6/6] Tests for ignoring invalid DayOne entries --- .../B40EE704E15846DE8D45C44118A4D512.doentry | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D512.doentry diff --git a/features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D512.doentry b/features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D512.doentry new file mode 100644 index 00000000..f005a1ff --- /dev/null +++ b/features/data/journals/bug153.dayone/entries/B40EE704E15846DE8D45C44118A4D512.doentry @@ -0,0 +1,52 @@ + + Creation Date + 2013-10-27T02:27:27Z + Creator + + Device Agent + iPhone/iPhone3,1 + Generation Date + 2013-10-27T07:02:27Z + Host Name + omrt104001 + OS Agent + iOS/7.0.3 + Software Agent + Day One (iOS)/1.11.4 + + Entry Text + This is not a valid plist. + Location + + Administrative Area + Östergötlands län + Country + Sverige + Latitude + 58.383400000000000 + Locality + City + Longitude + 15.577170000000000 + Place Name + Street + + Starred + + Time Zone + Europe/Stockholm + UUID + B40EE704E15846DE8D45C44118A4D511 + Weather + + Celsius + 12 + Description + Clear + Fahrenheit + 54 + IconName + sunnyn.png + + +