17
17
import requests
18
18
import instaloader
19
19
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"\n Profile information\n \n Name: { profile .full_name } \n Username: { profile .username } \n Posts: {
32
+ profile .mediacount } \n Followers: { profile .followers } \n Following: { profile .followees } \n " )
33
+
21
34
DISCORD_WEBHOOK_URL = input ("Enter the Discord webhook URL: " )
22
35
REFRESH_INTERVAL = 3600
23
36
24
- L = instaloader .Instaloader ()
25
37
26
38
def send_to_discord (post_details ):
27
39
"""Send a new Instagram post to Discord using a webhook."""
@@ -54,13 +66,15 @@ def send_to_discord(post_details):
54
66
response = requests .post (DISCORD_WEBHOOK_URL , json = data , timeout = 10 )
55
67
print ("Notification sent to Discord:" , response .status_code )
56
68
69
+
57
70
def check_for_new_posts ():
58
71
"""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 )
60
74
posts = profile .get_posts ()
61
75
62
76
until = datetime .now ()
63
- since = until .replace (second = until .second - REFRESH_INTERVAL )
77
+ since = until .replace (second = until .second - POST_REFRESH_INTERVAL )
64
78
65
79
for post in takewhile (lambda p : p .date > until , dropwhile (lambda p : p .date > since , posts )):
66
80
post_details = {
@@ -76,6 +90,7 @@ def check_for_new_posts():
76
90
send_to_discord (post_details )
77
91
break
78
92
93
+
79
94
while __name__ == "__main__" :
80
95
check_for_new_posts ()
81
- time .sleep (REFRESH_INTERVAL )
96
+ time .sleep (POST_REFRESH_INTERVAL )
0 commit comments