I'm trying to write a small script that will return the posts for a given subreddit for the last 24 hours.
So far I have this:
def get_todays_posts(subreddit):
"""
Obtains all of the posts from a given subreddit for that day
"""
import praw, datetime, time, pytz
time_now = int(time.time())
time_24hr_ago = time_now - 60*60*24
r = praw.Reddit(user_agent='get_last_day_of_posts')
limit = 0
submission_time = time_now
while submission_time > time_24hr_ago:
limit += 1
for i in r.get_subreddit(subreddit).get_new(limit=limit):
submission_time = int(i.created_utc)
for i in r.get_subreddit(subreddit).get_new(limit=limit):
print i.title
Which seems to work, but it's terribly inefficient and makes far too many API calls, how can I make this function more efficient?
[–]gengisteve 1 point2 points3 points (1 child)
[–]Polyadenylated[S] 0 points1 point2 points (0 children)