Initial commit.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.venv/
|
107
README.md
Normal file
107
README.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# rstat - Reddit Stock Ticker Analyzer Tool
|
||||
|
||||
This is a command-line tool to analyze stock ticker mentions across a predefined list of subreddits. It scrapes posts and comments, counts the number of times each ticker is mentioned, fetches the ticker's market capitalization, and will calculate a sentiment score for each mention.
|
||||
|
||||
## Features
|
||||
|
||||
* Scans a user-defined list of subreddits from a JSON configuration file.
|
||||
* Identifies stock tickers (e.g., `$AAPL`, `TSLA`) in Reddit posts and comments.
|
||||
* Fetches market capitalization for each identified ticker using the Yahoo Finance API.
|
||||
* Summarizes the findings in a clear, command-line-based report.
|
||||
* (Future) Performs sentiment analysis on each mention.
|
||||
|
||||
## Installation
|
||||
|
||||
Follow these steps to set up the project and its dependencies on your local machine.
|
||||
|
||||
### 1. Clone the Repository
|
||||
|
||||
First, clone this repository to your local machine (or simply download and create the files as described).
|
||||
|
||||
```bash
|
||||
git clone <your-repository-url>
|
||||
cd rstat
|
||||
```
|
||||
|
||||
### 2. Set Up a Python Virtual Environment
|
||||
|
||||
It is highly recommended to use a virtual environment to manage project-specific dependencies, preventing conflicts with your global Python installation.
|
||||
|
||||
**On macOS / Linux:**
|
||||
|
||||
```bash
|
||||
# Create a virtual environment named 'venv'
|
||||
python3 -m venv venv
|
||||
|
||||
# Activate the virtual environment
|
||||
source venv/bin/activate
|
||||
```
|
||||
*You will know it's active when you see `(venv)` at the beginning of your terminal prompt.*
|
||||
|
||||
**On Windows:**
|
||||
|
||||
```bash
|
||||
# Create a virtual environment named 'venv'
|
||||
python -m venv venv
|
||||
|
||||
# Activate the virtual environment
|
||||
.\venv\Scripts\activate
|
||||
```
|
||||
*You will know it's active when you see `(venv)` at the beginning of your command prompt.*
|
||||
|
||||
### 3. Install Dependencies
|
||||
|
||||
Once your virtual environment is activated, install the required Python libraries using the `requirements.txt` file.
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Before running the tool, you need to configure the list of subreddits you want to analyze.
|
||||
|
||||
1. Open the `subreddits.json` file.
|
||||
2. Modify the list of strings to include your desired subreddits.
|
||||
|
||||
**Example `subreddits.json`:**
|
||||
```json
|
||||
{
|
||||
"subreddits": [
|
||||
"wallstreetbets",
|
||||
"stocks",
|
||||
"investing",
|
||||
"pennystocks"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
To run the tool, execute the `main.py` script from the root directory of the project, passing the path to your configuration file as an argument.
|
||||
|
||||
Make sure your virtual environment is activated before running the script.
|
||||
|
||||
```bash
|
||||
python main.py subreddits.json
|
||||
```
|
||||
|
||||
### Expected Output
|
||||
|
||||
The tool will first confirm the loaded subreddits and then proceed with its analysis, printing the results directly to the terminal.
|
||||
|
||||
```
|
||||
Loading configuration...
|
||||
Successfully loaded 4 subreddits: wallstreetbets, stocks, investing, pennystocks
|
||||
------------------------------
|
||||
Testing market data functionality...
|
||||
Market Cap for AAPL: $2,912,488,124,416
|
||||
------------------------------
|
||||
Next up: Integrating the Reddit API to find tickers...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This `README.md` provides a clear and concise guide for anyone (including your future self) to get the project up and running quickly.
|
||||
|
||||
We are now ready to move on to the next implementation step. Shall we proceed with integrating the Reddit API using PRAW?
|
65
main.py
Normal file
65
main.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# main.py
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import yfinance as yf
|
||||
|
||||
def load_subreddits(filepath):
|
||||
"""Loads a list of subreddits from a JSON file."""
|
||||
try:
|
||||
with open(filepath, 'r') as f:
|
||||
data = json.load(f)
|
||||
return data.get("subreddits", [])
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The file '{filepath}' was not found.")
|
||||
return None
|
||||
except json.JSONDecodeError:
|
||||
print(f"Error: Could not decode JSON from '{filepath}'.")
|
||||
return None
|
||||
|
||||
def get_market_cap(ticker_symbol):
|
||||
"""Fetches the market capitalization for a given stock ticker."""
|
||||
try:
|
||||
ticker = yf.Ticker(ticker_symbol)
|
||||
market_cap = ticker.info.get('marketCap')
|
||||
if market_cap:
|
||||
# Formatting for better readability
|
||||
return f"${market_cap:,}"
|
||||
return "N/A"
|
||||
except Exception as e:
|
||||
# yfinance can sometimes fail for various reasons (e.g., invalid ticker)
|
||||
return "N/A"
|
||||
|
||||
def main():
|
||||
"""Main function to run the Reddit stock analysis tool."""
|
||||
parser = argparse.ArgumentParser(description="Analyze stock ticker mentions on Reddit.")
|
||||
parser.add_argument(
|
||||
"config_file",
|
||||
help="Path to the JSON file containing the list of subreddits."
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# --- Part 1: Load Configuration ---
|
||||
print("Loading configuration...")
|
||||
subreddits = load_subreddits(args.config_file)
|
||||
if not subreddits:
|
||||
print("No subreddits found in the configuration file. Exiting.")
|
||||
return
|
||||
|
||||
print(f"Successfully loaded {len(subreddits)} subreddits: {', '.join(subreddits)}")
|
||||
print("-" * 30)
|
||||
|
||||
|
||||
# --- Part 2: Test Market Data Fetching (Example) ---
|
||||
print("Testing market data functionality...")
|
||||
example_ticker = "AAPL"
|
||||
market_cap = get_market_cap(example_ticker)
|
||||
print(f"Market Cap for {example_ticker}: {market_cap}")
|
||||
print("-" * 30)
|
||||
|
||||
# In the next steps, we will add the Reddit scanning logic here.
|
||||
print("Next up: Integrating the Reddit API to find tickers...")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
yfinance
|
9
subreddits.json
Normal file
9
subreddits.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"subreddits": [
|
||||
"wallstreetbets",
|
||||
"stocks",
|
||||
"investing",
|
||||
"pennystocks",
|
||||
"Shortsqueeze"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user