mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 01:18:31 +02:00
Ignore unreadably DayOne entries
This commit is contained in:
parent
a5d345173a
commit
8604bf8455
1 changed files with 18 additions and 13 deletions
|
@ -24,6 +24,7 @@ import plistlib
|
||||||
import pytz
|
import pytz
|
||||||
import uuid
|
import uuid
|
||||||
import tzlocal
|
import tzlocal
|
||||||
|
from xml.parsers.expat import ExpatError
|
||||||
|
|
||||||
|
|
||||||
class Journal(object):
|
class Journal(object):
|
||||||
|
@ -332,20 +333,24 @@ class DayOne(Journal):
|
||||||
self.entries = []
|
self.entries = []
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
with open(filename, 'rb') as plist_entry:
|
with open(filename, 'rb') as plist_entry:
|
||||||
dict_entry = plistlib.readPlist(plist_entry)
|
|
||||||
try:
|
try:
|
||||||
timezone = pytz.timezone(dict_entry['Time Zone'])
|
dict_entry = plistlib.readPlist(plist_entry)
|
||||||
except (KeyError, pytz.exceptions.UnknownTimeZoneError):
|
except ExpatError:
|
||||||
timezone = tzlocal.get_localzone()
|
pass
|
||||||
date = dict_entry['Creation Date']
|
else:
|
||||||
date = date + timezone.utcoffset(date, is_dst=False)
|
try:
|
||||||
raw = dict_entry['Entry Text']
|
timezone = pytz.timezone(dict_entry['Time Zone'])
|
||||||
sep = re.search("[\n!?.]+", raw)
|
except (KeyError, pytz.exceptions.UnknownTimeZoneError):
|
||||||
title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
|
timezone = tzlocal.get_localzone()
|
||||||
entry = Entry.Entry(self, date, title, body, starred=dict_entry["Starred"])
|
date = dict_entry['Creation Date']
|
||||||
entry.uuid = dict_entry["UUID"]
|
date = date + timezone.utcoffset(date, is_dst=False)
|
||||||
entry.tags = [self.config['tagsymbols'][0] + tag for tag in dict_entry.get("Tags", [])]
|
raw = dict_entry['Entry Text']
|
||||||
self.entries.append(entry)
|
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()
|
self.sort()
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue