mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 12:08:31 +02:00
Merge 62ab6d36ff
into 9ffca1a7a6
This commit is contained in:
commit
058d4afbee
1 changed files with 12 additions and 0 deletions
|
@ -8,6 +8,7 @@ from . import time
|
||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import dateutil.parser
|
||||||
import sys
|
import sys
|
||||||
try:
|
try:
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
|
@ -112,6 +113,16 @@ class Journal(object):
|
||||||
def _parse(self, journal_txt):
|
def _parse(self, journal_txt):
|
||||||
"""Parses a journal that's stored in a string and returns a list of entries"""
|
"""Parses a journal that's stored in a string and returns a list of entries"""
|
||||||
|
|
||||||
|
def get_date_length(myline):
|
||||||
|
tmpdate=''
|
||||||
|
for i in [x for x in myline.split(' ') ]:
|
||||||
|
try:
|
||||||
|
dateutil.parser.parse(tmpdate + ' ' + i)
|
||||||
|
tmpdate = tmpdate + ' ' + i
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
return len(tmpdate.strip())
|
||||||
|
|
||||||
# Entries start with a line that looks like 'date title' - let's figure out how
|
# Entries start with a line that looks like 'date title' - let's figure out how
|
||||||
# long the date will be by constructing one
|
# long the date will be by constructing one
|
||||||
date_length = len(datetime.today().strftime(self.config['timeformat']))
|
date_length = len(datetime.today().strftime(self.config['timeformat']))
|
||||||
|
@ -123,6 +134,7 @@ class Journal(object):
|
||||||
for line in journal_txt.splitlines():
|
for line in journal_txt.splitlines():
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
try:
|
try:
|
||||||
|
date_length=get_date_length(line)
|
||||||
# try to parse line as date => new entry begins
|
# try to parse line as date => new entry begins
|
||||||
new_date = datetime.strptime(line[:date_length], self.config['timeformat'])
|
new_date = datetime.strptime(line[:date_length], self.config['timeformat'])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue