Extract habit counter from event tags additionally
This commit is contained in:
parent
18cdd34300
commit
e050acd288
1 changed files with 14 additions and 5 deletions
|
@ -9,14 +9,23 @@ def migrate(db, habitlist, events):
|
||||||
text = event["note"]
|
text = event["note"]
|
||||||
tags = extract_tags(text)
|
tags = extract_tags(text)
|
||||||
for habit in habitlist:
|
for habit in habitlist:
|
||||||
habit_tag = f"#{habit['description']}"
|
for tag in tags:
|
||||||
if habit_tag in tags:
|
if habit["description"] in tag[0]:
|
||||||
print(f"register event: {habit['name']} in {text} at {event['end']}")
|
print(
|
||||||
|
f"register event: {habit['name']} in {text} at {event['end']}"
|
||||||
|
)
|
||||||
add_to_database(c, habit["id"], event["end"])
|
add_to_database(c, habit["id"], event["end"])
|
||||||
|
|
||||||
|
|
||||||
def extract_tags(text, tagmarker="#"):
|
def extract_tags(text, tagmarker="#"):
|
||||||
found_tags = re.findall(rf"{tagmarker}\w+(?:\(\d+\))?", text)
|
"""Returns lists of tuples of all event tags found in text.
|
||||||
|
Parameters:
|
||||||
|
text (str): The text to search through.
|
||||||
|
tagmarker (str): Optional character marking beginning of tag, defaults to '#'.
|
||||||
|
Returns:
|
||||||
|
tags (list): List of tuples in the form [('tag', '3'), ('anothertag', '')].
|
||||||
|
"""
|
||||||
|
found_tags = re.findall(rf"{tagmarker}(\w+)(?:\((\d+)\))?", text)
|
||||||
return found_tags
|
return found_tags
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue