Utilizes TextBlob and PRAW to retrieve and analyze subreddit submission comments
Results will output to a CSV file at a defined folder path for use in Excel or other reporting tools
Install import requirements:
$ pip install praw
$ pip install textblob
$ python3 -m textblob.download_corpora
At this point you must create your own Reddit script application in your account's preferences page
You must also create a file named praw_config.py
in the same directory as sentiment.py
to house your Reddit credentials. You can do this in terminal with the following commands:
touch praw_config.py
echo $"user_agent = '[YOUR USER AGENT NAME]'" >> praw_config.py
echo $"client_id = '[YOUR CLIENT ID]'" >> praw_config.py
echo $"client_secret = '[YOUR CLIENT SECRET]'" >> praw_config.py
echo $"username = '[YOUR USERNAME]'" >> praw_config.py
echo $"password = '[YOUR PASSWORD]'" >> praw_config.py
Or alternatively create the file with an IDE/editor using the following code:
user_agent = '[YOUR USER AGENT NAME]'
client_id = '[YOUR CLIENT ID]'
client_secret = '[YOUR CLIENT SECRET]'
username = '[YOUR USER NAME]'
password = '[YOUR PASSWORD]'
Run the program from console, terminal, or an IDE:
python3 sentiment.py
Prompts are then required:
Analyze which Subreddit?: [Subreddit name]
How would you like to sort? (hot/top): [Sort filter]
<<IF TOP SELECTED>> Select top posts from? (hour/day/week/month/year/all): [Time filter]
How many posts would you like to analyze?: [Post count limit]
Define the path for the CSV file: [/user/folder/path/]
Results will be printed to the console:
Analyze which Subreddit?: news
How would you like to sort? (hot/top): top
Select top posts from? (hour/day/week/month/year/all): week
How many posts would you like to analyze?: 15
Define the path for the CSV file: /user/folder/path
Analyzing 15 top:week posts from /r/news
|██████████████████████████████████████████████████████████████████████| 100.0%
Success: CSV created in /user/folder/path/reddit_news_analysis_1522247876.csv
The CSV includes:
- Unique Submission ID
- Submission title
- Total (top level) comments
- Total positive comments
- Total neutral comments
- Total negative comments