mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Fixed time zone bug on dayone integration
This commit is contained in:
parent
41706c3cb5
commit
c13af8ccc4
2 changed files with 15 additions and 2 deletions
|
@ -7,6 +7,7 @@ import parsedatetime.parsedatetime as pdt
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
|
import pytz
|
||||||
try: import simplejson as json
|
try: import simplejson as json
|
||||||
except ImportError: import json
|
except ImportError: import json
|
||||||
import sys
|
import sys
|
||||||
|
@ -294,7 +295,10 @@ class DayOne(Journal):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
with open(filename) as plist_entry:
|
with open(filename) as plist_entry:
|
||||||
dict_entry = plistlib.readPlist(plist_entry)
|
dict_entry = plistlib.readPlist(plist_entry)
|
||||||
entry = self.new_entry(raw=dict_entry['Entry Text'], date=dict_entry['Creation Date'], sort=False)
|
timezone = pytz.timezone(dict_entry['Time Zone'])
|
||||||
|
date = dict_entry['Creation Date']
|
||||||
|
date = date + timezone.utcoffset(date)
|
||||||
|
entry = self.new_entry(raw=dict_entry['Entry Text'], date=date, sort=False)
|
||||||
entry.starred = dict_entry["Starred"]
|
entry.starred = dict_entry["Starred"]
|
||||||
entry.uuid = dict_entry["UUID"]
|
entry.uuid = dict_entry["UUID"]
|
||||||
# We're using new_entry to create the Entry object, which adds the entry
|
# We're using new_entry to create the Entry object, which adds the entry
|
||||||
|
@ -311,12 +315,20 @@ class DayOne(Journal):
|
||||||
# that have a uuid will be old ones, and only the one that doesn't will
|
# that have a uuid will be old ones, and only the one that doesn't will
|
||||||
# have a new one!
|
# have a new one!
|
||||||
if not hasattr(entry, "uuid"):
|
if not hasattr(entry, "uuid"):
|
||||||
|
timezone = os.popen("systemsetup -gettimezone").read()
|
||||||
|
try:
|
||||||
|
timezone = timezone.split(':')[1].strip()
|
||||||
|
except:
|
||||||
|
print("ERROR: Unable to get your time zone.")
|
||||||
|
sys.exit(-1)
|
||||||
|
utc_time = datetime.utcfromtimestamp(time.mktime(entry.date.timetuple()))
|
||||||
new_uuid = uuid.uuid1().hex
|
new_uuid = uuid.uuid1().hex
|
||||||
filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry")
|
filename = os.path.join(self.config['journal'], "entries", new_uuid+".doentry")
|
||||||
entry_plist = {
|
entry_plist = {
|
||||||
'Creation Date': entry.date,
|
'Creation Date': utc_time,
|
||||||
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
'Starred': entry.starred if hasattr(entry, 'starred') else False,
|
||||||
'Entry Text': entry.title+"\n"+entry.body,
|
'Entry Text': entry.title+"\n"+entry.body,
|
||||||
|
'Time Zone': timezone,
|
||||||
'UUID': new_uuid
|
'UUID': new_uuid
|
||||||
}
|
}
|
||||||
plistlib.writePlist(entry_plist, filename)
|
plistlib.writePlist(entry_plist, filename)
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -65,6 +65,7 @@ setup(
|
||||||
packages = ['jrnl'],
|
packages = ['jrnl'],
|
||||||
install_requires = [
|
install_requires = [
|
||||||
"parsedatetime>=1.1.2",
|
"parsedatetime>=1.1.2",
|
||||||
|
"pytz>=2013b",
|
||||||
"colorama>=0.2.5",
|
"colorama>=0.2.5",
|
||||||
"pycrypto>=2.6"
|
"pycrypto>=2.6"
|
||||||
] + ["pyreadline>=2.0"] if "win" in sys.platform else [],
|
] + ["pyreadline>=2.0"] if "win" in sys.platform else [],
|
||||||
|
|
Loading…
Add table
Reference in a new issue