Skip to content

Commit

Permalink
Merge pull request #26 from dedan/fix_parsing
Browse files Browse the repository at this point in the history
Fix parsing of newlines, closes #15
  • Loading branch information
Manuel Ebert authored and Manuel Ebert committed May 15, 2012
2 parents 8404dcc + f09fdd0 commit 6bf5c6e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions jrnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,19 @@ def parse(self, journal):
current_entry = None

for line in journal.split(os.linesep):
if line:
try:
new_date = datetime.fromtimestamp(time.mktime(time.strptime(line[:date_length], self.config['timeformat'])))
# make a journal entry of the current stuff first
if new_date and current_entry:
entries.append(current_entry)
# Start constructing current entry
current_entry = Entry(self, date=new_date, title=line[date_length+1:])
except ValueError:
# Happens when we can't parse the start of the line as an date.
# In this case, just append line to our body.
current_entry.body += line
try:
# try to parse line as date => new entry begins
new_date = datetime.strptime(line[:date_length], self.config['timeformat'])

# parsing successfull => save old entry and create new one
if new_date and current_entry:
entries.append(current_entry)
current_entry = Entry(self, date=new_date, title=line[date_length+1:])
except ValueError:
# Happens when we can't parse the start of the line as an date.
# In this case, just append line to our body.
current_entry.body += line + os.linesep

# Append last entry
if current_entry:
entries.append(current_entry)
Expand Down Expand Up @@ -459,8 +460,8 @@ def autocomplete(text, state):
elif args.tags: # get all tags
# Astute reader: should the following line leave you as puzzled as me the first time
# I came across this construction, worry not and embrace the ensuing moment of enlightment.
tags = [tag
for entry in journal.entries
tags = [tag
for entry in journal.entries
for tag in set(entry.tags)
]
# To be read: [for entry in journal.entries: for tag in set(entry.tags): tag]
Expand Down

0 comments on commit 6bf5c6e

Please sign in to comment.