Skip to content

Commit

Permalink
Improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLua authored Jul 2, 2024
1 parent c10ee97 commit b149f89
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/instagram_to_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit b149f89

Please sign in to comment.