From e050acd288b0744e9db6fdf722b6409defcb7c48 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 29 Aug 2021 11:22:55 +0200 Subject: [PATCH] Extract habit counter from event tags additionally --- loop/repetitions.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/loop/repetitions.py b/loop/repetitions.py index d265e80..fd020a3 100644 --- a/loop/repetitions.py +++ b/loop/repetitions.py @@ -9,14 +9,23 @@ def migrate(db, habitlist, events): text = event["note"] tags = extract_tags(text) for habit in habitlist: - habit_tag = f"#{habit['description']}" - if habit_tag in tags: - print(f"register event: {habit['name']} in {text} at {event['end']}") - add_to_database(c, habit["id"], event["end"]) + for tag in tags: + if habit["description"] in tag[0]: + print( + f"register event: {habit['name']} in {text} at {event['end']}" + ) + add_to_database(c, habit["id"], event["end"]) 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