Skip to content

Commit

Permalink
accept activities starting with '#'
Browse files Browse the repository at this point in the history
  • Loading branch information
ederag committed Nov 19, 2019
1 parent c3da6a2 commit 03288b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/hamster/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,21 @@ def parse_fact(text, phase=None, res=None, date=None):
if not m:
break
tag = m.group(1)
tags.append(tag)
# strip the matched string (including #)
backup_text = remaining_text
remaining_text = remaining_text[:m.start()]
# empty remaining text means that activity is starting with a '#'
if remaining_text:
tags.append(tag)
else:
remaining_text = backup_text
break
# put tags back in input order
res["tags"] = list(reversed(tags))
return parse_fact(remaining_text, "activity", res, date)

if "activity" in phases:
activity = re.split("[@|#|,]", text, 1)[0]
activity = re.split("[@|,]", text, 1)[0]
if looks_like_time(activity):
# want meaningful activities
return res
Expand Down
4 changes: 2 additions & 2 deletions tests/stuff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def test_description(self):

def test_tags(self):
# plain activity name
activity = Fact.parse("case, with added #de description #and, #some #tägs")
self.assertEqual(activity.activity, "case")
activity = Fact.parse("#case, with added #de description #and, #some #tägs")
self.assertEqual(activity.activity, "#case")
self.assertEqual(activity.description, "with added #de description")
self.assertEqual(set(activity.tags), set(["and", "some", "tägs"]))
assert not activity.category
Expand Down

0 comments on commit 03288b1

Please sign in to comment.