r/redditdev Oct 25 '24

Submission maximum number and subreddit.new(limit=####) PRAW

It seems that the maximum number of submissions I can fetch is 1000:

limit – The number of content entries to fetch. If limit is None, then fetch as many entries as possible. Most of Reddit’s listings contain a maximum of 1000 items, and are returned 100 at a time. This class will automatically issue all necessary requests (default: 100).

Can anyone shed some more light on this limit? What happens with None? If I'm using .new(limit=None) how many submissions am I actually getting at most? Also; how many API requests am I making? Just whatever number I type in divided by 100?

Use case: I want the URLs of as many submissions as possible. These URLs are then passed through random.choice(URLs) to get a singular random submission link from the subreddit.

Actual code. Get submission titles (image submissions):

def get_image_links(reddit: praw.Reddit) -> list:
    sub = reddit.subreddit('example')
    image_candidates = []
    for image_submission in sub.new(limit=None):
        if (re.search('(i.redd.it|i.imgur.com)', image_submission.url):
            image_candidates.append(image_submissions.url)
    return image_candidates

These image links are then saved to a variable which is then later passed onto the function that generates the bot's actual functionality (a comment reply):

def generate_reply_text(image_links: list) -> str:
    ...
    bot_reply_text += f'''[{link_text}]({random.choice(image_links)})'''
    ...
3 Upvotes

View all comments

Show parent comments

2

u/Watchful1 RemindMeBot & UpdateMeBot Oct 25 '24

It looks like this is a fairly new subreddit that only has about 250 posts today. So you won't hit the limit anytime soon.

That said, I would recommend getting the full list and storing it locally instead of fetching it again each time there's a request.

1

u/MustaKotka Oct 25 '24

Oh I think I actually misunderstood something you said. I'm fetching the full 1000 every 1h and using that until the next refresh.

2

u/Watchful1 RemindMeBot & UpdateMeBot Oct 25 '24

That definitely is better than doing it every request. But I'm more talking about saving it permanently so even once the subreddit gets more than 1000 you don't lose any.

For something like this you don't need a complex database, unless you're already using one. You could just write it to a json file.

And checking for new submissions once an hour is likely plenty for that as well.

1

u/MustaKotka Oct 25 '24

Got it. Thanks for your help! You are amazing!