How to Read Reddit with Python

in #python7 years ago (edited)

reddit.png

<p dir="auto">Outside of Steemit I expect a heck of a lot of you are also members of Reddit. <p dir="auto">Keeping up with your favourite subreddit can be tricky - what if the best submissions came to you, rather than you going and looking? <h3>Reddit API Wrapper for Python <p dir="auto">Reddit has a decent API, and there is a Python wrapper called <a href="https://praw.readthedocs.io" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">PRAW (Python Reddit API Wrapper). PRAW is available via pip <p dir="auto"><code>pip install praw <h3>API Keys <p dir="auto">To get started all you need to do is go into your account and set up your new app as a script. <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmQSNBUbd8PtwhK8JyN8gUmP3m7LU4NqCzjA9VgRSLMim9/Screenshot%20from%202018-05-15%2014-20-52.png" alt="Screenshot from 2018-05-15 14-20-52.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmQSNBUbd8PtwhK8JyN8gUmP3m7LU4NqCzjA9VgRSLMim9/Screenshot%20from%202018-05-15%2014-20-52.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmQSNBUbd8PtwhK8JyN8gUmP3m7LU4NqCzjA9VgRSLMim9/Screenshot%20from%202018-05-15%2014-20-52.png 2x" /> <p dir="auto">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. <p dir="auto">From there the code is very simple <h3>Code <pre><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() <p dir="auto"><span><img src="https://images.hive.blog/768x0/https://cdn.discordapp.com/attachments/383256479056134146/446022370608676864/makerhacks.png" srcset="https://images.hive.blog/768x0/https://cdn.discordapp.com/attachments/383256479056134146/446022370608676864/makerhacks.png 1x, https://images.hive.blog/1536x0/https://cdn.discordapp.com/attachments/383256479056134146/446022370608676864/makerhacks.png 2x" />