A Python script designed to fetch and analyze a Reddit user's activity, looking for various patterns and potential red flags that might indicate bot-like behavior, an account being used for advertising, or other inauthentic activity. This tool leverages the PRAW library to interact with the Reddit API and NLTK for sentiment analysis.
This script provides a suite of analytical tools to gain insights into a Reddit user's posting history and profile. By examining account age, karma, posting frequency, content repetition, sentiment, and specific keywords, it aims to highlight behaviors that deviate from typical human usage patterns. This can be useful for moderation research, understanding online communities, or simply satisfying curiosity about Reddit account behaviors.
The script is designed to be run from the command line and interactively prompts for necessary credentials and the target username.
- Reddit API Integration: Connects to the Reddit API using PRAW.
- Dynamic Inputs:
- Prompts for the target Reddit username to analyze.
- Securely prompts for the Reddit API script credentials (username & password for the script's own authentication).
- Profile Analysis:
- Fetches and displays account creation date and calculates account age.
- Retrieves and shows link karma, comment karma, and total karma.
- Basic checks for new accounts or old accounts with very low karma.
- Simple username pattern recognition (e.g., containing "bot", "gpt", or common generated patterns).
- Activity Fetching:
- Retrieves a user's recent posts and comments (up to a configurable limit).
- Inactivity Detection:
- Identifies and reports significant periods of inactivity between posts/comments.
- Advertising Keyword Spotting:
- Scans post titles and bodies (and comment bodies) for a predefined list of advertising-related keywords.
- Performs this check on activities immediately following a long inactivity gap and on a general sample of recent activity.
- Posting Pattern Analysis:
- Activity Spread: Compares the start of fetched activity relative to the account creation date (to spot potentially long-dormant accounts revived).
- Content Repetition: Detects and reports repeated post titles or comment bodies.
- Subreddit Diversity: Provides information on the number of unique subreddits the user is active in (based on fetched data).
- Sentiment Analysis:
- Utilizes NLTK's VADER to analyze the sentiment (positive, negative, neutral, compound) of a sample of the user's posts and comments.
- Reports average sentiment scores and flags overwhelmingly one-sided or monotone sentiment.
- Console Reporting: Outputs analysis results directly to the console with clear sections and "Red Flag" indicators.
- Python 3.x
- PRAW (Python Reddit API Wrapper): For interacting with the Reddit API.
- NLTK (Natural Language Toolkit): Specifically
SentimentIntensityAnalyzer(VADER) for sentiment analysis. - Standard Python Libraries:
datetime,getpass,collections.
-
Python Installation: Ensure you have Python 3.6 or newer installed. You can download it from python.org. During installation on Windows, make sure to check the box "Add Python to PATH."
-
Clone the Repository (Optional): If you have this project in a Git repository:
git clone <your-repository-url> cd <repository-name>
Otherwise, just ensure the
reddit_analyzer.pyscript is in your desired directory. -
Install Dependencies: Open your command line (Terminal, Command Prompt, PowerShell) and install the required Python libraries:
pip install praw nltk
Or, if you use
pip3:pip3 install praw nltk
-
Download NLTK VADER Lexicon: The script attempts to do this automatically on first run if the lexicon is missing. However, if that fails, you may need to download it manually. Run the following in a Python interpreter (type
pythonorpython3in your command line to open one, then exit withquit()after):import nltk nltk.download('vader_lexicon')
-
Reddit API Credentials for the Script: Your script needs its own API credentials to talk to Reddit.
- Create a Reddit App:
- Log in to your Reddit account.
- Go to https://www.reddit.com/prefs/apps.
- Scroll down and click "are you a developer? create an app..."
- Fill in the details:
- Name: e.g., "MyRedditAnalysisTool" or "UsernameAnalyzer"
- Type: Select "script".
- Description: e.g., "Script for analyzing Reddit user activity."
- About URL: (Optional) Can be left blank.
- Redirect URI: Use
http://localhost:8080
- Click "create app."
- Get Your Credentials: After creating the app, Reddit will show you:
- A Client ID (often labeled "personal use script" and looks like a random string of characters).
- A Client Secret (another random string).
- Update the Script: Open the
reddit_analyzer.pyfile and replace the placeholder values forCLIENT_IDandCLIENT_SECRETwith the ones you just obtained:Important: Keep yourCLIENT_ID = "YOUR_CLIENT_ID_HERE" # Replace with your actual Client ID CLIENT_SECRET = "YOUR_CLIENT_SECRET_HERE" # Replace with your actual Client Secret USER_AGENT = "UsernameAnalyzer/0.1 by u/YourRedditUsername" # Customize with your app name and Reddit username
CLIENT_SECRETconfidential!
- Create a Reddit App:
- Navigate to the directory where
reddit_analyzer.pyis saved using your command line. - Run the script using Python:
Or, if you use
python reddit_analyzer.py
python3:python3 reddit_analyzer.py
- Follow the Prompts: The script will then ask you to enter:
- The Reddit username you want to analyze.
- Your Reddit API script credentials:
- "Your Reddit Username (for API script)": This is the username of the Reddit account that owns the API app you created.
- "Your Reddit Password (for API script, typing will be hidden)": This is the password for that Reddit account. If this account has 2FA enabled, you MUST use an "app password" generated on Reddit, not your regular account password.
The script will print its findings to the console, organized into sections:
- Profile & Karma Analysis: Account age, karma scores, and related flags.
- Posting Pattern Analysis: Activity spread, content repetition, subreddit diversity.
- Sentiment Analysis: Average sentiment scores and flags for extreme or monotone sentiment.
- Inactivity Period Analysis: Details of long gaps between activities.
- Basic Advertising Keyword Scan: Items flagged for containing promotional keywords, especially after inactivity.
Look for "🚩 Red Flag:" and "ⓘ Info:" messages that highlight potentially noteworthy findings.
- Not Foolproof: This script provides heuristics and indicators, not definitive proof of bot activity or intent. Sophisticated bots can evade simple detection methods.
- API Rate Limits: The script fetches a limited number of recent posts/comments (default 200 each) to respect Reddit's API rate limits and for performance. It does not analyze a user's entire history if it's very long.
- Subjectivity: Some "red flags" (e.g., what constitutes "low karma" for an "old account") are based on arbitrary thresholds in the script and may need adjustment for different contexts.
- Keyword Lists: The advertising keyword list is basic and may produce false positives or miss some types of promotion. It can be customized.
- Sentiment Analysis Context: VADER is good for social media but may misinterpret sarcasm or complex nuances.
- This tool is intended for research, personal understanding, and responsible use.
- Do not use this tool to harass, witch-hunt, or make definitive public accusations against users.
- Always respect user privacy and Reddit's Terms of Service.
- The data collected is based on publicly available user activity.
- More sophisticated NLP for linguistic analysis (e.g., syntactic complexity, topic modeling).
- Granular temporal analysis (e.g., posting times, inter-post delay consistency).
- Configuration file for thresholds and keyword lists.
- Option to output reports to a file (e.g., CSV, JSON, HTML).
- Graph analysis of user interactions (if feasible and within API limits).
- More advanced URL/domain analysis for shared links.
This project is open-source. Consider adding a license if you distribute it, e.g., the MIT License