I am facing a heroku 30s time out error with my django webapp. The reason it is taking long is because of the views variables created (reddit api onto context)
Here is the code for the same.
def home(request):
reddit = praw.Reddit(client_id='myclientid', client_secret='mysecretcode',
user_agent='user agent name')
hot_posts = reddit.subreddit('AskReddit').top(time_filter="day", limit=7)
x = []
y = []
for post in hot_posts:
x.append(post.title)
y.append(post.url)
print(x)
print(y)
z = []
for url in y:
comments = []
submission = reddit.submission(url=url)
submission.comments.replace_more(limit=0)
for count in range(10):
comments.append(submission.comments[count].body)
z.append(comments)
top_EarthPorn = reddit.subreddit('EarthPorn').top(limit=100)
EarthPorn_links = []
for post in top_EarthPorn:
EarthPorn_links.append(post.url)
request.session['EarthPorn_links'] = EarthPorn_links
return render(request, template_name='base.html', context=context)
How do i make sure the context dict data is being created every hour or so as a background process? which libraries can one use to achieve so