@@ -94,6 +94,13 @@ def closure_check_regex(arg_value):
94
94
action = "store_true" ,
95
95
)
96
96
parser .add_argument ("--version" , action = "version" , version = "%(prog)s " + version )
97
+ parser .add_argument (
98
+ "-p" ,
99
+ "--catchup" ,
100
+ help = "send the last latest posts on startup regardless of time" ,
101
+ type = int ,
102
+ default = 0 ,
103
+ )
97
104
args = parser .parse_args ()
98
105
99
106
# Set the logger to debug if verbose is enabled
@@ -211,7 +218,7 @@ async def send_to_discord(post: Post):
211
218
logger .info ("New post sent to Discord successfully." )
212
219
213
220
214
- async def check_for_new_posts ():
221
+ async def check_for_new_posts (catchup : int = args . catchup ):
215
222
"""Check for new Instagram posts and send them to Discord"""
216
223
217
224
logger .info ("Checking for new posts" )
@@ -225,12 +232,27 @@ async def check_for_new_posts():
225
232
226
233
new_posts_found = False
227
234
235
+ async def send_post (post : Post ):
236
+ logger .info ("New post found: https://www.instagram.com/p/%s" , post .shortcode )
237
+ await send_to_discord (post )
238
+
239
+ if catchup > 0 :
240
+ logger .info ("Sending last %s posts on startup..." , catchup )
241
+ posts_to_send = []
242
+ for post in takewhile (lambda _ : catchup > 0 , posts ):
243
+ posts_to_send .append (post )
244
+ catchup -= 1
245
+
246
+ # Reverse the posts to send oldest first
247
+ for post in reversed (posts_to_send ):
248
+ await send_post (post )
249
+ sleep (2 ) # Avoid 30 requests per minute rate limit
250
+
228
251
for post in takewhile (
229
252
lambda p : p .date > until , dropwhile (lambda p : p .date > since , posts )
230
253
):
231
254
new_posts_found = True
232
- logger .info ("New post found: https://www.instagram.com/p/%s" , post .shortcode )
233
- await send_to_discord (post )
255
+ await send_post (post )
234
256
sleep (2 ) # Avoid 30 requests per minute rate limit
235
257
236
258
if not new_posts_found :
0 commit comments