Ever wonder how a subreddit feels about a certain subject? This script can provide insight. Input the name of a subreddit and a key word/phrase to view bar plot representations of the sentiment analysis.
sentiment.py [-h] [--show-neutral] subreddit key
positional arguments:
subreddit name of subreddit
key word or phrase you want to run by the subreddit
optional arguments:
-h, --help show this help message and exit
--show-neutral, -n include neutral words in barplot
- Python3 (3.9.5)
- See the official webpage for download information.
- Conda
- You are welcome to use other package management systems, but I ran into a lot of trouble with pip on a Mac M1. I installed conda through Miniforge.
git clone https://github.com/hein-j/reddit-sentiment-analysis.git
cd
into project root- Install dependencies (into a virtual environment if you wish)
- For conda:
conda create --prefix ./venv --file requirements.txt
and thenconda activate ./venv
- If you run into trouble or are not using conda, the dependencies are:
- praw
- nltk
- pandas
- emoji
- spacy
- plotly
- For conda:
- Download 'wordnet' and 'vader_lexicon' from nltk (See instructions here)
- Download spacy model:
python -m spacy download en_core_web_sm
- Create a reddit app (See here for help)
- Create a
praw.ini
file in project root. Name the sitebot
. Includeclient_id
,client_secret
, anduser_agent
. (See here for help) - You should now be good to go 🤘
Issues & pull requests are most welcome.
Distributed under the MIT License. See License for more information.
Big thanks to this article by Jason LZP for getting this project started.