From b149f89c3c10a08d55e501f8159cc090cde91bb4 Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Tue, 2 Jul 2024 12:32:06 +0000 Subject: [PATCH] Improve formatting --- src/instagram_to_discord.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/instagram_to_discord.py b/src/instagram_to_discord.py index 9d28e17..8aac0c2 100644 --- a/src/instagram_to_discord.py +++ b/src/instagram_to_discord.py @@ -9,27 +9,26 @@ If the login fails, you may need to use import_firefox_session.py to get your session file and login using that. """ -import instaloader -import requests import time +import requests +import instaloader -INSTAGRAM_PROFILE = input("Enter the Instagram account you want monitor: ") -WEBHOOK_URL = input("Enter the Discord webhook URL: ") - -refresh_interval = 600 # How often to check for new posts (in seconds) +TARGET_INSTAGRAM_PROFILE = input("Enter the Instagram account you want monitor: ") +DISCORD_WEBHOOK_URL = input("Enter the Discord webhook URL: ") +POST_REFRESH_INTERVAL = 600 # How often to check for new posts (in seconds) # Get instance L = instaloader.Instaloader() def send_to_discord(post_url): """Send the Instagram post URL to Discord.""" - data = {"content": f"New post from {INSTAGRAM_PROFILE}: {post_url}"} - response = requests.post(WEBHOOK_URL, json=data) + data = {"content": f"New post from {TARGET_INSTAGRAM_PROFILE}: {post_url}"} + response = requests.post(DISCORD_WEBHOOK_URL, json=data, timeout=10) print("Notification sent to Discord:", response.status_code) def check_for_new_posts(): """Check for new posts and notify on Discord.""" - profile = instaloader.Profile.from_username(L.context, INSTAGRAM_PROFILE) + profile = instaloader.Profile.from_username(L.context, TARGET_INSTAGRAM_PROFILE) for post in profile.get_posts(): # Assuming you're running this script regularly, check the latest post send_to_discord("https://instagram.com/p/" + post.shortcode) @@ -38,4 +37,4 @@ def check_for_new_posts(): # Every 10 minutes while __name__ == "__main__": check_for_new_posts() - time.sleep(refresh_interval) # Sleep for 600 seconds (10 minutes) + time.sleep(POST_REFRESH_INTERVAL) # Sleep for 600 seconds (10 minutes)