mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-21 05:28:31 +02:00
[DayOne] brings back extended DayOne attributes
This commit is contained in:
parent
ef9615b904
commit
b7f1464d1a
1 changed files with 54 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
||||||
from . import Entry
|
from . import Entry
|
||||||
from . import Journal
|
from . import Journal
|
||||||
from . import time as jrnl_time
|
from . import time as jrnl_time
|
||||||
|
from . import __title__ # 'jrnl'
|
||||||
|
from . import __version__
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -14,6 +16,8 @@ import pytz
|
||||||
import uuid
|
import uuid
|
||||||
import tzlocal
|
import tzlocal
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
|
import socket
|
||||||
|
import platform
|
||||||
|
|
||||||
|
|
||||||
class DayOne(Journal.Journal):
|
class DayOne(Journal.Journal):
|
||||||
|
@ -70,6 +74,35 @@ class DayOne(Journal.Journal):
|
||||||
for tag in dict_entry.get("Tags", [])
|
for tag in dict_entry.get("Tags", [])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
"""Extended DayOne attributes"""
|
||||||
|
try:
|
||||||
|
entry.creator_device_agent = dict_entry['Creator']['Device Agent']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
entry.creator_generation_date = dict_entry['Creator']['Generation Date']
|
||||||
|
except:
|
||||||
|
entry.creator_generation_date = date
|
||||||
|
try:
|
||||||
|
entry.creator_host_name = dict_entry['Creator']['Host Name']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
entry.creator_os_agent = dict_entry['Creator']['OS Agent']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
entry.creator_software_agent = dict_entry['Creator']['Software Agent']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
entry.location = dict_entry['Location']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
entry.weather = dict_entry['Weather']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
self.entries.append(entry)
|
self.entries.append(entry)
|
||||||
self.sort()
|
self.sort()
|
||||||
return self
|
return self
|
||||||
|
@ -84,6 +117,16 @@ class DayOne(Journal.Journal):
|
||||||
|
|
||||||
if not hasattr(entry, "uuid"):
|
if not hasattr(entry, "uuid"):
|
||||||
entry.uuid = uuid.uuid1().hex
|
entry.uuid = uuid.uuid1().hex
|
||||||
|
if not hasattr(entry, "creator_device_agent"):
|
||||||
|
entry.creator_device_agent = '' # iPhone/iPhone5,3
|
||||||
|
if not hasattr(entry, "creator_generation_date"):
|
||||||
|
entry.creator_generation_date = utc_time
|
||||||
|
if not hasattr(entry, "creator_host_name"):
|
||||||
|
entry.creator_host_name = socket.gethostname()
|
||||||
|
if not hasattr(entry, "creator_os_agent"):
|
||||||
|
entry.creator_os_agent = '{}/{}'.format(platform.system(), platform.release())
|
||||||
|
if not hasattr(entry, "creator_software_agent"):
|
||||||
|
entry.creator_software_agent = '{}/{}'.format(__title__, __version__)
|
||||||
|
|
||||||
fn = (
|
fn = (
|
||||||
Path(self.config["journal"])
|
Path(self.config["journal"])
|
||||||
|
@ -101,10 +144,21 @@ class DayOne(Journal.Journal):
|
||||||
tag.strip(self.config["tagsymbols"]).replace("_", " ")
|
tag.strip(self.config["tagsymbols"]).replace("_", " ")
|
||||||
for tag in entry.tags
|
for tag in entry.tags
|
||||||
],
|
],
|
||||||
|
'Creator': {'Device Agent': entry.creator_device_agent,
|
||||||
|
'Generation Date': entry.creator_generation_date,
|
||||||
|
'Host Name': entry.creator_host_name,
|
||||||
|
'OS Agent': entry.creator_os_agent,
|
||||||
|
'Software Agent': entry.creator_software_agent}
|
||||||
}
|
}
|
||||||
|
if hasattr(entry, 'location'):
|
||||||
|
entry_plist['Location'] = entry.location
|
||||||
|
if hasattr(entry, 'weather'):
|
||||||
|
entry_plist['Weather'] = entry.weather
|
||||||
|
|
||||||
# plistlib expects a binary object
|
# plistlib expects a binary object
|
||||||
with fn.open(mode="wb") as f:
|
with fn.open(mode="wb") as f:
|
||||||
plistlib.dump(entry_plist, f, fmt=plistlib.FMT_XML, sort_keys=False)
|
plistlib.dump(entry_plist, f, fmt=plistlib.FMT_XML, sort_keys=False)
|
||||||
|
|
||||||
for entry in self._deleted_entries:
|
for entry in self._deleted_entries:
|
||||||
filename = os.path.join(
|
filename = os.path.join(
|
||||||
self.config["journal"], "entries", entry.uuid + ".doentry"
|
self.config["journal"], "entries", entry.uuid + ".doentry"
|
||||||
|
|
Loading…
Add table
Reference in a new issue