Skip to content

Commit

Permalink
Fix getting posts
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLua authored Jul 14, 2024
1 parent 0cbeb15 commit a102c1f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/instawebhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a102c1f

Please sign in to comment.