Skip to content

Commit

Permalink
Add placeholders for message content
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLua authored Jul 25, 2024
1 parent 2de7707 commit 96e0b75
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/instawebhooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def closure_check_regex(arg_value):

# Ensure that a message content is provided if no embed is enabled
if args.no_embed and args.message_content == "":
logger.critical("error: Cannot send an empty message")
logger.critical("error: Cannot send an empty message. No message content provided.")
raise SystemExit(
"No message content provided. Please provide a message content with the --message-content flag or an embed by removing the --no-embed flag."
"Please provide a message content with the --message-content flag."
)


Expand All @@ -113,13 +113,26 @@ def create_webhook_json(post: Post):
footer_icon_url = (
"https://www.instagram.com/static/images/ico/favicon-192.png/68d99ba29cc8.png"
)

placeholders = {
"{post_url}": "https://www.instagram.com/" + post.shortcode + "/",
"{owner_url}": "https://www.instagram.com/" + post.owner_username + "/",
"{owner_name}": post.owner_profile.full_name,
"{owner_username}": post.owner_username,
"{post_caption}": post.caption,
"{post_shortcode}": post.shortcode,
"{post_image_url}": post.url,
}

# Replace placeholders in the message content
for placeholder, value in placeholders.items():
args.message_content = args.message_content.replace(placeholder, value)

# Create the webhook JSON object
if args.no_embed:
webhook_json = {
"content": args.message_content,
"attachments": [],
}
# Send only the message content
webhook_json = {"content": args.message_content}
else:
# Send the message content and the post embed
webhook_json = {
"content": args.message_content,
"embeds": [
Expand Down

0 comments on commit 96e0b75

Please sign in to comment.