Created
October 9, 2022 13:36
-
-
Save capjamesg/70ab3fd2eefac7cbb955a1b5deda0efe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
note = "I am presently having coffee with @example. #coffee #lunch #breakfast" #* 10000 | |
person_tags_reference = { | |
"example": ("Example Person", "example.com/bio"), | |
} | |
tags = ["coffee", "lunch", "breakfast"] | |
tags = {tag: tag for tag in tags} | |
note_tags = re.findall(r"#(\w+)", note) | |
person_tags = re.findall(r"@(\w+)", note) | |
all_tags = list(set(note_tags)) | |
for tag in all_tags: | |
if tags.get(tag): | |
note = note.replace( | |
"#" + tag, f"<a href='https://jamesg.blog/tag/{tags[tag]}'>#{tag}</a>" | |
) | |
for tag in list(set(person_tags)): | |
if person_tags_reference.get(tag): | |
note = note.replace( | |
"@" + tag, | |
f"<a href='https://jamesg.blog/tag/{person_tags_reference[tag][1]}'>@{person_tags_reference[tag][0]}</a>", | |
) | |
print(note) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment