Skip to content

A script to retrieve subreddit posts by various parameters and analyze comment sentiment

Notifications You must be signed in to change notification settings

jasongreely/reddit-sentiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

reddit-sentiment

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

Installation

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]'

Usage

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

About

A script to retrieve subreddit posts by various parameters and analyze comment sentiment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages