This commit is contained in:
GitHub Merge Button 2012-05-14 13:00:01 -07:00
commit 7987c7307f

29
jrnl.py
View file

@ -173,18 +173,19 @@ class Journal:
current_entry = None current_entry = None
for line in journal.split(os.linesep): for line in journal.split(os.linesep):
if line: try:
try: # try to parse line as date => new entry begins
new_date = datetime.fromtimestamp(time.mktime(time.strptime(line[:date_length], self.config['timeformat']))) new_date = datetime.strptime(line[:date_length], self.config['timeformat'])
# make a journal entry of the current stuff first
if new_date and current_entry: # parsing successfull => save old entry and create new one
entries.append(current_entry) if new_date and current_entry:
# Start constructing current entry entries.append(current_entry)
current_entry = Entry(self, date=new_date, title=line[date_length+1:]) current_entry = Entry(self, date=new_date, title=line[date_length+1:])
except ValueError: except ValueError:
# Happens when we can't parse the start of the line as an date. # Happens when we can't parse the start of the line as an date.
# In this case, just append line to our body. # In this case, just append line to our body.
current_entry.body += line current_entry.body += line + os.linesep
# Append last entry # Append last entry
if current_entry: if current_entry:
entries.append(current_entry) entries.append(current_entry)
@ -459,8 +460,8 @@ if __name__ == "__main__":
elif args.tags: # get all tags elif args.tags: # get all tags
# Astute reader: should the following line leave you as puzzled as me the first time # 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. # I came across this construction, worry not and embrace the ensuing moment of enlightment.
tags = [tag tags = [tag
for entry in journal.entries for entry in journal.entries
for tag in set(entry.tags) for tag in set(entry.tags)
] ]
# To be read: [for entry in journal.entries: for tag in set(entry.tags): tag] # To be read: [for entry in journal.entries: for tag in set(entry.tags): tag]