From 8604bf8455431e40026186d368fe7e4dcc47ec63 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Wed, 16 Apr 2014 14:34:39 -0400 Subject: [PATCH] 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):