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