From a102c1f888665b2658a279b4598784f9efeca14f Mon Sep 17 00:00:00 2001 From: Ryan Luu Date: Sun, 14 Jul 2024 07:12:46 +0000 Subject: [PATCH] Fix getting posts --- src/instawebhooks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/instawebhooks.py b/src/instawebhooks.py index ad3180e..9308bbe 100644 --- a/src/instawebhooks.py +++ b/src/instawebhooks.py @@ -5,6 +5,8 @@ import re import logging from argparse import ArgumentTypeError, ArgumentParser +from datetime import datetime, timedelta +from itertools import dropwhile, takewhile from time import sleep from instaloader import Instaloader, Profile import requests @@ -125,7 +127,10 @@ def check_for_new_posts(): posts = Profile.from_username( Instaloader().context, args.instagram_username).get_posts() - for post in posts: + since = datetime.now() - timedelta(seconds=args.refresh_interval) + until = datetime.now() + + for post in takewhile(lambda p: p.date > until, dropwhile(lambda p: p.date > since, posts)): logger.info('New post found: https://instagram.com/p/%s', post.shortcode) send_to_discord(post)