Skip to content

Commit

Permalink
Use type refinement for post_caption
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLua authored Aug 20, 2024
1 parent 8cb8932 commit 31ed2a0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/instawebhooks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 31ed2a0

Please sign in to comment.