r/redditdev • u/MustaKotka • 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 isNone
, 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)})'''
...
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.