Skip to content

Commit 466d337

Browse files
authored
Add profile information
1 parent 1cda73d commit 466d337

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/instagram_to_discord.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@
1717
import requests
1818
import instaloader
1919

20-
TARGET_INSTAGRAM_PROFILE = input("Enter the Instagram account you want monitor: ")
20+
L = instaloader.Instaloader()
21+
22+
POST_REFRESH_INTERVAL = 3600 # Seconds
23+
24+
# Terrible and repetitive code, but it works for now.
25+
TARGET_INSTAGRAM_PROFILE = input(
26+
"Enter the Instagram account you want to create a webhook for: ")
27+
28+
profile = instaloader.Profile.from_username(
29+
L.context, TARGET_INSTAGRAM_PROFILE)
30+
31+
print(f"\nProfile information\n\nName: {profile.full_name}\nUsername: {profile.username}\nPosts: {
32+
profile.mediacount}\nFollowers: {profile.followers}\nFollowing: {profile.followees}\n")
33+
2134
DISCORD_WEBHOOK_URL = input("Enter the Discord webhook URL: ")
2235
REFRESH_INTERVAL = 3600
2336

24-
L = instaloader.Instaloader()
2537

2638
def send_to_discord(post_details):
2739
"""Send a new Instagram post to Discord using a webhook."""
@@ -54,13 +66,15 @@ def send_to_discord(post_details):
5466
response = requests.post(DISCORD_WEBHOOK_URL, json=data, timeout=10)
5567
print("Notification sent to Discord:", response.status_code)
5668

69+
5770
def check_for_new_posts():
5871
"""Check for new Instagram posts and send them to Discord."""
59-
profile = instaloader.Profile.from_username(L.context, TARGET_INSTAGRAM_PROFILE)
72+
profile = instaloader.Profile.from_username(
73+
L.context, TARGET_INSTAGRAM_PROFILE)
6074
posts = profile.get_posts()
6175

6276
until = datetime.now()
63-
since = until.replace(second=until.second-REFRESH_INTERVAL)
77+
since = until.replace(second=until.second-POST_REFRESH_INTERVAL)
6478

6579
for post in takewhile(lambda p: p.date > until, dropwhile(lambda p: p.date > since, posts)):
6680
post_details = {
@@ -76,6 +90,7 @@ def check_for_new_posts():
7690
send_to_discord(post_details)
7791
break
7892

93+
7994
while __name__ == "__main__":
8095
check_for_new_posts()
81-
time.sleep(REFRESH_INTERVAL)
96+
time.sleep(POST_REFRESH_INTERVAL)

0 commit comments

Comments
 (0)