Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLua authored Jul 7, 2024
1 parent e18f35c commit b941e44
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/instagram_to_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,38 @@
DISCORD_WEBHOOK_URL = input("Enter your Discord webhook URL: ")


def send_to_discord(post_details):
def send_to_discord(post):
"""Send a new Instagram post to Discord using a webhook."""

post_url = "https://instagram.com/p/" + post.shortcode + "/"
image_url = post.url
author_name = profile.username
author_icon_url = profile.profile_pic_url
post_description = post.caption
post_timestamp = post.date
author_fullname = profile.full_name

icon_url = "https://www.instagram.com/static/images/ico/favicon-192.png/68d99ba29cc8.png"
data = {
"content": f"{post_details['post_url']}",
"content": f"{post_url}",
"embeds": [
{
"title": post_details['author_fullname'],
"description": post_details['post_description'],
"url": post_details['post_url'],
"title": author_fullname,
"description": post_description,
"url": post_url,
"color": 13500529,
"timestamp": post_details['post_timestamp'].strftime("%Y-%m-%dT%H:%M:%S"),
"timestamp": post_timestamp.strftime("%Y-%m-%dT%H:%M:%S"),
"author": {
"name": post_details['author_name'],
"url": f"https://www.instagram.com/{post_details['author_name']}/",
"icon_url": post_details['author_icon_url']
"name": author_name,
"url": f"https://www.instagram.com/{author_name}/",
"icon_url": author_icon_url
},
"footer": {
"text": "Instagram",
"icon_url": icon_url
},
"image": {
"url": post_details['image_url']
"url": image_url
}
}
],
Expand All @@ -77,18 +86,8 @@ def check_for_new_posts():
posts = profile.get_posts()

for post in posts:
post_details = {
"post_url": "https://instagram.com/p/" + post.shortcode + "/",
"image_url": post.url,
"author_name": profile.username,
"author_icon_url": profile.profile_pic_url,
"post_description": post.caption,
"post_timestamp": post.date,
"author_fullname": profile.full_name
}

print(f"New post found: {post_details['post_url']}")
send_to_discord(post_details)
print(f"New post found: https://instagram.com/p/{post.shortcode}/")
send_to_discord(post)
break


Expand Down

0 comments on commit b941e44

Please sign in to comment.