From 8cb893285103427ea89a68774c35191cfa38898b Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Mon, 19 Aug 2024 23:59:57 +0000 Subject: [PATCH 1/3] Add hyperlinks for mentions --- src/instawebhooks/__main__.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/instawebhooks/__main__.py b/src/instawebhooks/__main__.py index 218bce2..f3d3017 100644 --- a/src/instawebhooks/__main__.py +++ b/src/instawebhooks/__main__.py @@ -144,15 +144,17 @@ async def create_embed(post: Post): post_image_file = File(io.BytesIO(post_image_bytes), "post_image.webp") profile_pic_file = File(io.BytesIO(profile_pic_bytes), "profile_pic.webp") - # Replace hashtags with clickable links - if post.caption is None: - post_caption = "" - else: - post_caption = re.sub( - r"#([a-zA-Z0-9]+\b)", - r"[#\1](https://www.instagram.com/explore/tags/\1)", - post.caption, - ) + # Format the post caption with clickable links for mentions and hashtags + post_caption = re.sub( + r"#([a-zA-Z0-9]+\b)", + r"[#\1](https://www.instagram.com/explore/tags/\1)", + post.caption, + ) + post_caption = re.sub( + r"@([a-zA-Z0-9_]+\b)", + r"[@\1](https://www.instagram.com/\1)", + post_caption, + ) embed = Embed( color=13500529, From 31ed2a090b55b8f9f7f96a2a002d670334c53b9d Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Tue, 20 Aug 2024 00:06:32 +0000 Subject: [PATCH 2/3] Use type refinement for post_caption --- src/instawebhooks/__main__.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/instawebhooks/__main__.py b/src/instawebhooks/__main__.py index f3d3017..a186791 100644 --- a/src/instawebhooks/__main__.py +++ b/src/instawebhooks/__main__.py @@ -145,16 +145,18 @@ async def create_embed(post: Post): profile_pic_file = File(io.BytesIO(profile_pic_bytes), "profile_pic.webp") # Format the post caption with clickable links for mentions and hashtags - post_caption = re.sub( - r"#([a-zA-Z0-9]+\b)", - r"[#\1](https://www.instagram.com/explore/tags/\1)", - post.caption, - ) - post_caption = re.sub( - r"@([a-zA-Z0-9_]+\b)", - r"[@\1](https://www.instagram.com/\1)", - post_caption, - ) + post_caption = post.caption + if post_caption is str: + post_caption = re.sub( + r"#([a-zA-Z0-9]+\b)", + r"[#\1](https://www.instagram.com/explore/tags/\1)", + post_caption, + ) + post_caption = re.sub( + r"@([a-zA-Z0-9_]+\b)", + r"[@\1](https://www.instagram.com/\1)", + post_caption, + ) embed = Embed( color=13500529, From 3ce0e1d9eae5d299adb0a83376eebcec9ee488db Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Tue, 20 Aug 2024 00:11:02 +0000 Subject: [PATCH 3/3] Fix post.caption --- src/instawebhooks/__main__.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/instawebhooks/__main__.py b/src/instawebhooks/__main__.py index a186791..b680984 100644 --- a/src/instawebhooks/__main__.py +++ b/src/instawebhooks/__main__.py @@ -145,18 +145,17 @@ async def create_embed(post: Post): profile_pic_file = File(io.BytesIO(profile_pic_bytes), "profile_pic.webp") # Format the post caption with clickable links for mentions and hashtags - post_caption = post.caption - if post_caption is str: - post_caption = re.sub( - r"#([a-zA-Z0-9]+\b)", - r"[#\1](https://www.instagram.com/explore/tags/\1)", - post_caption, - ) - post_caption = re.sub( - r"@([a-zA-Z0-9_]+\b)", - r"[@\1](https://www.instagram.com/\1)", - post_caption, - ) + post_caption = post.caption or "" + post_caption = re.sub( + r"#([a-zA-Z0-9]+\b)", + r"[#\1](https://www.instagram.com/explore/tags/\1)", + post_caption, + ) + post_caption = re.sub( + r"@([a-zA-Z0-9_]+\b)", + r"[@\1](https://www.instagram.com/\1)", + post_caption, + ) embed = Embed( color=13500529,