Skip to content

Commit

Permalink
feat: Avoid errors on tag not found in habit matching
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonee committed Oct 23, 2024
1 parent 11a7cb0 commit 34d2912
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tasks/apps/tree/habits.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def note_to_habit_tracked_tuple(item, habit_names, habits):
# Assume first line is actually important for the habit tracked note
return (occured, habit, item.split("\n")[0])

def note_to_habit_tracked_tuple_or_none(item, habit_names, habits):
try:
return note_to_habit_tracked_tuple(item, habit_names, habits)
except ValueError:
return None

def habits_line_to_habits_tracked(line):
items = PATTERN.split(' ' + line)
Expand All @@ -45,9 +50,8 @@ def habits_line_to_habits_tracked(line):
habits = list(Habit.objects.all())
habit_names = list(map(lambda x: x.tagname, habits))

return list(map(
lambda x: note_to_habit_tracked_tuple(x, habit_names, habits),
return list(filter(None, map(
lambda x: note_to_habit_tracked_tuple_or_none(x, habit_names, habits),
items
))

)))

0 comments on commit 34d2912

Please sign in to comment.