How to Keep Track of Top Posts on Reddit with Free API

import requests
import pandas as pd
subreddit = ['30PlusSkinCare','Skincare_Addiction','AsianBeauty','MakeupAddiction']
limit = 400
timeframe = 'week' #hour, day, week, month, year, all
listing = 'best' # controversial, best, hot, new, random, rising,top
  1. Import packages.
  • Top is the raw score, upvotes minus downvotes.
  • Best is more about the proportion of upvotes to downvotes.
  • Controversial gives high scores to posts that have a lot of both upvotes and downvotes — a lot of people like it but a lot of people also dislike it.
  • Hot are posts that have gotten a lot of votes recently, either up or down, so it shows relatively new posts that are getting attention.
  • Rising is what is getting a lot of activity (comments/upvotes) right now.
  • New sorts post by the time of submission with the newest at the top of the page.
def get_reddit(subreddit,listing,limit,timeframe):
base_url = f'{subreddit}/{listing}.json?limit={limit}&t={timeframe}'
request = requests.get(base_url, headers = {'User-agent': 'yourbot'})
print('An Error Occured')
return request.json()
def get_results(r):

myDict = {}
for post in r['data']['children']:
myDict[post['data']['title']] = {'url':post['data']['url'],'score':post['data']['score'],'comments':post['data']['num_comments']}
df = pd.DataFrame.from_dict(myDict, orient='index')
return df
df_f=pd.DataFrame()for i in range(len(subreddit)):
df = get_results(result)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store



Books | Marketing | Data Viz | Analytics & Experimentation | Entrepreneurship 💡Founder of | Blog: