mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
[Dayone] Add Creator section to dayone import and YAML export
This commit is contained in:
parent
91368c7b63
commit
0fcf078c1c
3 changed files with 74 additions and 11 deletions
|
@ -4,6 +4,8 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
from . import Entry
|
||||
from . import Journal
|
||||
from . import __title__ # 'jrnl'
|
||||
from . import __version__
|
||||
import os
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
@ -14,6 +16,8 @@ import pytz
|
|||
import uuid
|
||||
import tzlocal
|
||||
from xml.parsers.expat import ExpatError
|
||||
import socket
|
||||
import platform
|
||||
|
||||
|
||||
class DayOne(Journal.Journal):
|
||||
|
@ -53,6 +57,27 @@ class DayOne(Journal.Journal):
|
|||
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", [])]
|
||||
"""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:
|
||||
pass
|
||||
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
|
||||
self.entries.append(entry)
|
||||
self.sort()
|
||||
return self
|
||||
|
@ -61,17 +86,34 @@ class DayOne(Journal.Journal):
|
|||
"""Writes only the entries that have been modified into plist files."""
|
||||
for entry in self.entries:
|
||||
if entry.modified:
|
||||
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
|
||||
filename = os.path.join(self.config['journal'], "entries", entry.uuid.upper() + ".doentry")
|
||||
|
||||
if not hasattr(entry, "uuid"):
|
||||
entry.uuid = uuid.uuid1().hex
|
||||
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
|
||||
filename = os.path.join(self.config['journal'], "entries", entry.uuid + ".doentry")
|
||||
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__)
|
||||
|
||||
entry_plist = {
|
||||
'Creation Date': utc_time,
|
||||
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
||||
'Entry Text': entry.title + "\n" + entry.body,
|
||||
'Time Zone': str(tzlocal.get_localzone()),
|
||||
'UUID': entry.uuid,
|
||||
'Tags': [tag.strip(self.config['tagsymbols']).replace("_", " ") for tag in entry.tags]
|
||||
'UUID': entry.uuid.upper(),
|
||||
'Tags': [tag.strip(self.config['tagsymbols']).replace("_", " ") 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,
|
||||
'Sofware Agent': entry.creator_software_agent}
|
||||
}
|
||||
plistlib.writePlist(entry_plist, filename)
|
||||
for entry in self._deleted_entries:
|
||||
|
|
|
@ -11,4 +11,4 @@ __title__ = 'jrnl'
|
|||
__version__ = '2.0.0-rc1'
|
||||
__author__ = 'Manuel Ebert'
|
||||
__license__ = 'MIT License'
|
||||
__copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'
|
||||
__copyright__ = 'Copyright 2013 - 2015 Manuel Ebert'
|
||||
|
|
|
@ -58,12 +58,33 @@ class YAMLExporter(TextExporter):
|
|||
if warn_on_heading_level is True:
|
||||
print("{}WARNING{}: Headings increased past H6 on export - {} {}".format("\033[33m", "\033[0m", date_str, entry.title), file=sys.stderr)
|
||||
|
||||
return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{body} {space}".format(
|
||||
date=date_str,
|
||||
title=entry.title,
|
||||
stared=entry.starred,
|
||||
tags=', '.join([tag[1:] for tag in entry.tags]),
|
||||
body=newbody,
|
||||
dayone_attributes = ''
|
||||
if hasattr(entry, "uuid"):
|
||||
dayone_attributes += 'uuid: ' + entry.uuid + '\n'
|
||||
if hasattr(entry, 'creator_device_agent') or \
|
||||
hasattr(entry, 'creator_generation_date') or \
|
||||
hasattr(entry, 'creator_host_name') or \
|
||||
hasattr(entry, 'creator_os_agent') or \
|
||||
hasattr(entry, 'creator_software_agent'):
|
||||
dayone_attributes += 'creator:\n'
|
||||
if hasattr(entry, 'creator_device_agent'):
|
||||
dayone_attributes += ' device agent: ' + entry.creator_device_agent + '\n'
|
||||
if hasattr(entry, 'creator_generation_date'):
|
||||
dayone_attributes += ' generation date: ' + str(entry.creator_generation_date) + '\n'
|
||||
if hasattr(entry, 'creator_host_name'):
|
||||
dayone_attributes += ' host name: ' + entry.creator_host_name + '\n'
|
||||
if hasattr(entry, 'creator_os_agent'):
|
||||
dayone_attributes += ' os agent: ' + entry.creator_os_agent + '\n'
|
||||
if hasattr(entry, 'creator_software_agent'):
|
||||
dayone_attributes += ' software agent: ' + entry.creator_software_agent + '\n'
|
||||
|
||||
return "title: {title}\ndate: {date}\nstared: {stared}\ntags: {tags}\n{dayone} {body} {space}".format(
|
||||
date = date_str,
|
||||
title = entry.title,
|
||||
stared = entry.starred,
|
||||
tags = ', '.join([tag[1:] for tag in entry.tags]),
|
||||
dayone = dayone_attributes,
|
||||
body = newbody,
|
||||
space=""
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue