Creating a trending topics application that displays a wordcloud of the most frequent words in the comment sections of a given subreddit, using Reddit's API.
1. Setting up a Python Virtual Environment (venv):
In your project's directory, run the following commands:
- Windows:
python -m venv myenv
- Linux/Mac:
python3 -m venv myenv
(make sure to activate venv in your terminal to install dependencies)
- Windows:
myenv/Scripts/Activate
- Linux/Mac:
source myenv/bin/activate
- Windows/Linux/Mac
deactivate
2. Installing Required Dependencies:
pip install praw
pip install wordcloud
pip install python-dotenv
pip install nltk
To install NLTK data, create a python terminal typing python/python3
command and run:
import nltk
nltk.download('stopwords')
3. Setting up Reddit's API Registration:
To setup your API registration, follow the instructions in this TUTORIAL.
4. Securing API keys with '.env' file:
create a file named '.env' and replace the values of your API keys in the environment variables. Here's an example:REDDIT_CLIENT_ID=RedDitCliEntID0123456789
REDDIT_CLIENT_SECRET=clIeNTseCret0123456789
REDDIT_USER_AGENT=subreddit trending topics by u/your_reddits_username
export REDDIT_CLIENT_ID="RedDitCliEntID0123456789"
export REDDIT_CLIENT_SECRET="clIeNTseCret0123456789"
export REDDIT_USER_AGENT="subreddit trending topics by u/your_reddits_username"
This wordcloud is an output example of the most commented words in the 'python' subreddit in May 2024, between 05-01 and 05-24
These are the top 15 most commented words, each one associated with it's frequency:
- 's': 576
- 'python': 545
- 'n': 535
- 't': 533
- 'use': 470
- 'like': 396
- 'code': 367
- 'https': 362
- 'would': 307
- 'using': 239
- 'com': 222
- 'need': 212
- 'also': 211
- 'one': 209
- 'm': 187