


First we connect to Reddit by calling the praw.Reddit function and storing it in a variable. PRAW stands for Python Reddit API Wrapper, so it makes it very easy for us to access Reddit data. On Linux, the shebang line is #! /usr/bin/python3. On Windows, the shebang line is #! python3. It varies a little bit from Windows to Macs to Linux, so replace the first line accordingly: The shebang line is just some code that helps the computer locate python in the memory. You only need to worry about this if you are considering running the script from the command line. The “shebang line” is what you see on the very first line of the script #! usr/bin/env python3. It should look like: #! usr/bin/env python3 The best practice is to put your imports at the top of the script, right after the shebang line, which starts with #!. We will be using only one of Python’s built-in modules, datetime, and two third-party modules, Pandas and Praw. The “shebang line” and importing packages and modules Copy and paste your 14-characters personal use script and 27-character secret key somewhere safe. Hit create app and now you are ready to use the OAuth2 authorization to connect to the API and start scraping. If you have any doubts, refer to Praw documentation. Also make sure you select the “script” option and don’t forget to put in the redirect uri field. Pick a name for your application and add a description for reference. Go to this page and click create app or create another app button at the bottom left. The very first thing you’ll need to do is “Create an App” within Reddit to get the OAuth2 keys to access the API.

You can also run scripts from the command-line.
