How to Read Reddit with Python

in #python7 years ago (edited)

reddit.png

Outside of Steemit I expect a heck of a lot of you are also members of Reddit.

Keeping up with your favourite subreddit can be tricky - what if the best submissions came to you, rather than you going and looking?

Reddit API Wrapper for Python

Reddit has a decent API, and there is a Python wrapper called PRAW (Python Reddit API Wrapper). PRAW is available via pip

pip install praw

API Keys

To get started all you need to do is go into your account and set up your new app as a script.

Screenshot from 2018-05-15 14-20-52.png

You will be given your unique API details, that you can then use to gain read access. If you want more than that you will need oAuth and/or your login.

From there the code is very simple

Code

import praw

reddit = praw.Reddit(client_id='',
                     client_secret='',
                     user_agent='')

# get top 20 from 3dprinting

for submission in reddit.subreddit('3dprinting').hot(limit=20):
    print(submission.title)
    print(submission.url)
    print()

Coin Marketplace

STEEM 0.19
TRX 0.18
JST 0.033
BTC 89216.15
ETH 3099.59
USDT 1.00
SBD 2.80