Add deep dive function to get more into each single stock.
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
# rstat_tool/dashboard.py
|
# rstat_tool/dashboard.py
|
||||||
|
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
|
# --- FIX #1: Import the new function we need ---
|
||||||
from .database import (
|
from .database import (
|
||||||
get_overall_summary,
|
get_overall_summary,
|
||||||
get_subreddit_summary,
|
get_subreddit_summary,
|
||||||
get_all_scanned_subreddits
|
get_all_scanned_subreddits,
|
||||||
|
get_deep_dive_details
|
||||||
)
|
)
|
||||||
|
|
||||||
app = Flask(__name__, template_folder='../templates')
|
app = Flask(__name__, template_folder='../templates')
|
||||||
@@ -32,17 +34,22 @@ def inject_subreddits():
|
|||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
"""The handler for the main dashboard page."""
|
"""The handler for the main dashboard page."""
|
||||||
# --- CHANGE HERE: Limit the data to the top 10 ---
|
|
||||||
tickers = get_overall_summary(limit=10)
|
tickers = get_overall_summary(limit=10)
|
||||||
return render_template("index.html", tickers=tickers)
|
return render_template("index.html", tickers=tickers)
|
||||||
|
|
||||||
@app.route("/subreddit/<name>")
|
@app.route("/subreddit/<name>")
|
||||||
def subreddit_dashboard(name):
|
def subreddit_dashboard(name):
|
||||||
"""A dynamic route for per-subreddit dashboards."""
|
"""A dynamic route for per-subreddit dashboards."""
|
||||||
# --- CHANGE HERE: Limit the data to the top 10 ---
|
|
||||||
tickers = get_subreddit_summary(name, limit=10)
|
tickers = get_subreddit_summary(name, limit=10)
|
||||||
return render_template("subreddit.html", tickers=tickers, subreddit_name=name)
|
return render_template("subreddit.html", tickers=tickers, subreddit_name=name)
|
||||||
|
|
||||||
|
@app.route("/deep-dive/<symbol>")
|
||||||
|
def deep_dive(symbol):
|
||||||
|
"""The handler for the deep-dive page for a specific ticker."""
|
||||||
|
# --- FIX #2: Call the function directly, without the 'database.' prefix ---
|
||||||
|
posts = get_deep_dive_details(symbol)
|
||||||
|
return render_template("deep_dive.html", posts=posts, symbol=symbol)
|
||||||
|
|
||||||
def start_dashboard():
|
def start_dashboard():
|
||||||
"""The main function called by the 'rstat-dashboard' command."""
|
"""The main function called by the 'rstat-dashboard' command."""
|
||||||
print("Starting Flask server...")
|
print("Starting Flask server...")
|
||||||
|
@@ -52,6 +52,20 @@ def initialize_db():
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS posts (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
post_id TEXT NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
post_url TEXT,
|
||||||
|
subreddit_id INTEGER,
|
||||||
|
post_timestamp INTEGER,
|
||||||
|
comment_count INTEGER,
|
||||||
|
avg_comment_sentiment REAL,
|
||||||
|
FOREIGN KEY (subreddit_id) REFERENCES subreddits (id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
print("Database initialized successfully.")
|
print("Database initialized successfully.")
|
||||||
@@ -196,3 +210,39 @@ def get_all_scanned_subreddits():
|
|||||||
results = conn.execute("SELECT DISTINCT name FROM subreddits ORDER BY name ASC;").fetchall()
|
results = conn.execute("SELECT DISTINCT name FROM subreddits ORDER BY name ASC;").fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return [row['name'] for row in results]
|
return [row['name'] for row in results]
|
||||||
|
|
||||||
|
def add_or_update_post_analysis(conn, post_data):
|
||||||
|
"""
|
||||||
|
Inserts a new post analysis record or updates an existing one.
|
||||||
|
This prevents duplicate entries for the same post.
|
||||||
|
"""
|
||||||
|
cursor = conn.cursor()
|
||||||
|
# Use the UNIQUE post_id to replace old data with new on conflict
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO posts (post_id, title, post_url, subreddit_id, post_timestamp, comment_count, avg_comment_sentiment)
|
||||||
|
VALUES (:post_id, :title, :post_url, :subreddit_id, :post_timestamp, :comment_count, :avg_comment_sentiment)
|
||||||
|
ON CONFLICT(post_id) DO UPDATE SET
|
||||||
|
comment_count = excluded.comment_count,
|
||||||
|
avg_comment_sentiment = excluded.avg_comment_sentiment;
|
||||||
|
""",
|
||||||
|
post_data
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
def get_deep_dive_details(ticker_symbol):
|
||||||
|
"""
|
||||||
|
Gets all analyzed posts that mention a specific ticker.
|
||||||
|
"""
|
||||||
|
conn = get_db_connection()
|
||||||
|
query = """
|
||||||
|
SELECT DISTINCT p.*, s.name as subreddit_name FROM posts p
|
||||||
|
JOIN mentions m ON p.post_id = m.post_id
|
||||||
|
JOIN tickers t ON m.ticker_id = t.id
|
||||||
|
JOIN subreddits s ON p.subreddit_id = s.id
|
||||||
|
WHERE t.symbol = ?
|
||||||
|
ORDER BY p.post_timestamp DESC;
|
||||||
|
"""
|
||||||
|
results = conn.execute(query, (ticker_symbol,)).fetchall()
|
||||||
|
conn.close()
|
||||||
|
return results
|
85
rstat_tool/format_blacklist.py
Normal file
85
rstat_tool/format_blacklist.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# The initial unsorted set of words.
|
||||||
|
# Note: In Python, a 'set' is inherently unordered, but we define it here for clarity.
|
||||||
|
COMMON_WORDS_BLACKLIST = {
|
||||||
|
"401K", "403B", "457B", "ABOUT", "ABOVE", "ADAM", "AEDT", "AEST", "AH", "AI",
|
||||||
|
"ALL", "ALPHA", "ALSO", "AM", "AMA", "AMEX", "AND", "ANY", "AR", "ARE",
|
||||||
|
"AROUND", "ASAP", "ASS", "ASSET", "AT", "ATH", "ATL", "ATM", "AUD", "BABY",
|
||||||
|
"BAG", "BAGS", "BE", "BEAR", "BELOW", "BETA", "BIG", "BIS", "BLEND", "BOE",
|
||||||
|
"BOJ", "BOMB", "BOND", "BOTH", "BOTS", "BRB", "BRL", "BS", "BST", "BTC",
|
||||||
|
"BTW", "BULL", "BUST", "BUT", "BUY", "BUZZ", "CAD", "CALL", "CAN", "CAP",
|
||||||
|
"CEO", "CEST", "CET", "CFO", "CHF", "CHIPS", "CIA", "CLOSE", "CNY", "COME",
|
||||||
|
"COST", "COULD", "CPAP", "CPI", "CST", "CTB", "CTO", "CYCLE", "CZK", "DAO",
|
||||||
|
"DATE", "DAX", "DAY", "DCA", "DD", "DEBT", "DIA", "DIV", "DJIA", "DKK",
|
||||||
|
"DM", "DO", "DOE", "DOGE", "DONT", "DR", "EACH", "EARLY", "EARN", "ECB",
|
||||||
|
"EDGAR", "EDIT", "EDT", "END", "EOD", "EOW", "EOY", "EPS", "ER", "ESG",
|
||||||
|
"EST", "ETF", "ETH", "EU", "EUR", "EV", "EVEN", "EVERY", "FAQ", "FAR",
|
||||||
|
"FAST", "FBI", "FDA", "FIHTX", "FINRA", "FINT", "FINTX", "FINTY", "FOMC", "FOMO",
|
||||||
|
"FOR", "FRAUD", "FRG", "FROM", "FSPSX", "FTSE", "FUCK", "FUD", "FULL", "FUND",
|
||||||
|
"FXAIX", "FXIAX", "FY", "FYI", "FZROX", "GAIN", "GBP", "GDP", "GET", "GL",
|
||||||
|
"GLHF", "GMT", "GO", "GOAL", "GOAT", "GOING", "GPT", "GPU", "GRAB", "GTG",
|
||||||
|
"HALF", "HAS", "HATE", "HAVE", "HEAR", "HEDGE", "HIGH", "HINT", "HKD", "HODL",
|
||||||
|
"HOLD", "HOUR", "HSA", "HUF", "IF", "II", "IMHO", "IMO", "IN", "INR",
|
||||||
|
"IP", "IPO", "IRA", "IRS", "IS", "ISM", "IST", "IT", "ITM", "IV",
|
||||||
|
"IVV", "IWM", "JPOW", "JPY", "JST", "JUST", "KARMA", "KEEP", "KNOW", "KO",
|
||||||
|
"KRW", "LARGE", "LAST", "LATE", "LATER", "LBO", "LEAP", "LEAPS", "LETS", "LFG",
|
||||||
|
"LIKE", "LIMIT", "LMAO", "LOL", "LONG", "LOOK", "LOSS", "LOVE", "LOW", "M&A",
|
||||||
|
"MA", "MAKE", "MAX", "MC", "ME", "MID", "MIGHT", "MIN", "ML", "MOASS",
|
||||||
|
"MONTH", "MORE", "MSK", "MUST", "MXN", "MY", "NATO", "NEAR", "NEED", "NEVER",
|
||||||
|
"NEW", "NEXT", "NFA", "NFT", "NGMI", "NIGHT", "NO", "NOK", "NONE", "NOT",
|
||||||
|
"NOW", "NSA", "NULL", "NYSE", "NZD", "OEM", "OF", "OK", "OLD", "ON",
|
||||||
|
"OP", "OR", "OS", "OTC", "OTM", "OUGHT", "OUT", "OVER", "OWN", "PC",
|
||||||
|
"PDT", "PE", "PEAK", "PEG", "PEW", "PLAN", "PLN", "PM", "PMI", "POS",
|
||||||
|
"PPI", "PR", "PRICE", "PROFIT", "PSA", "PST", "PT", "PUT", "Q1", "Q2",
|
||||||
|
"Q3", "Q4", "QQQ", "RBA", "RBNZ", "RE", "REAL", "REIT", "REKT", "RH",
|
||||||
|
"RIP", "RISK", "ROE", "ROFL", "ROI", "ROTH", "RSD", "RUB", "RULE", "SAVE",
|
||||||
|
"SCALP", "SCAM", "SCHB", "SEC", "SEE", "SEK", "SELL", "SEP", "SGD", "SHALL",
|
||||||
|
"SHARE", "SHORT", "SL", "SMALL", "SO", "SOLIS", "SOME", "SOON", "SP", "SPAC",
|
||||||
|
"SPEND", "SPLG", "SPX", "SPY", "START", "STILL", "STOCK", "STOP", "SWING", "TAKE",
|
||||||
|
"TERM", "THAT", "THE", "THINK", "THIS", "TIME", "TITS", "TL", "TL;DR", "TLDR",
|
||||||
|
"TO", "TODAY", "TOTAL", "TRADE", "TREND", "TRUE", "TRY", "TTYL", "TWO", "UI",
|
||||||
|
"UK", "UNDER", "UP", "US", "USA", "USD", "UTC", "VALUE", "VOO", "VR",
|
||||||
|
"VTI", "WAGMI", "WANT", "WATCH", "WAY", "WE", "WEB3", "WEEK", "WHO", "WHY",
|
||||||
|
"WILL", "WORTH", "WOULD", "WSB", "WTF", "YES", "YET", "YIELD", "YOLO", "YOU",
|
||||||
|
"YOUR", "YTD", "ZAR"
|
||||||
|
}
|
||||||
|
|
||||||
|
def format_and_print_list(word_set, words_per_line=10):
|
||||||
|
"""
|
||||||
|
Sorts a set of words and prints it in a specific format.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
word_set (set): The set of words to process.
|
||||||
|
words_per_line (int): The number of words to print on each line.
|
||||||
|
"""
|
||||||
|
# 1. Convert the set to a list to ensure order, and sort it alphabetically.
|
||||||
|
# The set is also used to remove any duplicates from the initial list.
|
||||||
|
sorted_words = sorted(list(word_set))
|
||||||
|
|
||||||
|
# 2. Start printing the output
|
||||||
|
print("COMMON_WORDS_BLACKLIST = {")
|
||||||
|
|
||||||
|
# 3. Iterate through the sorted list and print words, respecting the line limit
|
||||||
|
for i in range(0, len(sorted_words), words_per_line):
|
||||||
|
# Get a chunk of words for the current line
|
||||||
|
line_chunk = sorted_words[i:i + words_per_line]
|
||||||
|
|
||||||
|
# Format each word with double quotes
|
||||||
|
formatted_words = [f'"{word}"' for word in line_chunk]
|
||||||
|
|
||||||
|
# Join the words with a comma and a space
|
||||||
|
line_content = ", ".join(formatted_words)
|
||||||
|
|
||||||
|
# Add a trailing comma if it's not the last line
|
||||||
|
is_last_line = (i + words_per_line) >= len(sorted_words)
|
||||||
|
if not is_last_line:
|
||||||
|
line_content += ","
|
||||||
|
|
||||||
|
# Print the indented line
|
||||||
|
print(f" {line_content}")
|
||||||
|
|
||||||
|
# 4. Print the closing brace
|
||||||
|
print("}")
|
||||||
|
|
||||||
|
# --- Main execution ---
|
||||||
|
if __name__ == "__main__":
|
||||||
|
format_and_print_list(COMMON_WORDS_BLACKLIST)
|
@@ -1,4 +1,4 @@
|
|||||||
# main.py
|
# rstat_tool/main.py
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
@@ -9,7 +9,6 @@ import praw
|
|||||||
import yfinance as yf
|
import yfinance as yf
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# Import local modules
|
|
||||||
from . import database
|
from . import database
|
||||||
from .ticker_extractor import extract_tickers
|
from .ticker_extractor import extract_tickers
|
||||||
from .sentiment_analyzer import get_sentiment_score
|
from .sentiment_analyzer import get_sentiment_score
|
||||||
@@ -17,7 +16,6 @@ from .sentiment_analyzer import get_sentiment_score
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
MARKET_CAP_REFRESH_INTERVAL = 86400
|
MARKET_CAP_REFRESH_INTERVAL = 86400
|
||||||
|
|
||||||
# (load_subreddits, get_market_cap, get_reddit_instance functions are unchanged)
|
|
||||||
def load_subreddits(filepath):
|
def load_subreddits(filepath):
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'r') as f:
|
with open(filepath, 'r') as f:
|
||||||
@@ -38,11 +36,13 @@ def get_reddit_instance():
|
|||||||
client_secret = os.getenv("REDDIT_CLIENT_SECRET")
|
client_secret = os.getenv("REDDIT_CLIENT_SECRET")
|
||||||
user_agent = os.getenv("REDDIT_USER_AGENT")
|
user_agent = os.getenv("REDDIT_USER_AGENT")
|
||||||
if not all([client_id, client_secret, user_agent]):
|
if not all([client_id, client_secret, user_agent]):
|
||||||
print("Error: Reddit API credentials not found.")
|
print("Error: Reddit API credentials not found in .env file.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# --- THIS IS THE CORRECTED LINE ---
|
||||||
|
# The argument is 'client_secret', not 'secret_client'.
|
||||||
return praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
|
return praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
|
||||||
|
|
||||||
# --- UPDATED: Function now accepts post_limit and comment_limit ---
|
|
||||||
def scan_subreddits(reddit, subreddits_list, post_limit=25, comment_limit=100):
|
def scan_subreddits(reddit, subreddits_list, post_limit=25, comment_limit=100):
|
||||||
"""Scans subreddits, analyzes posts and comments, and stores results in the database."""
|
"""Scans subreddits, analyzes posts and comments, and stores results in the database."""
|
||||||
conn = database.get_db_connection()
|
conn = database.get_db_connection()
|
||||||
@@ -54,8 +54,10 @@ def scan_subreddits(reddit, subreddits_list, post_limit=25, comment_limit=100):
|
|||||||
subreddit = reddit.subreddit(subreddit_name)
|
subreddit = reddit.subreddit(subreddit_name)
|
||||||
print(f"Scanning r/{subreddit_name}...")
|
print(f"Scanning r/{subreddit_name}...")
|
||||||
|
|
||||||
for submission in subreddit.new(limit=post_limit):
|
for submission in subreddit.hot(limit=post_limit):
|
||||||
# --- 1. Process the Post Title and Body ---
|
|
||||||
|
# --- LOGIC PART 1: PROCESS INDIVIDUAL MENTIONS ---
|
||||||
|
# 1a. Process the Post Title and Body for mentions
|
||||||
post_text = submission.title + " " + submission.selftext
|
post_text = submission.title + " " + submission.selftext
|
||||||
tickers_in_post = extract_tickers(post_text)
|
tickers_in_post = extract_tickers(post_text)
|
||||||
post_sentiment = get_sentiment_score(submission.title)
|
post_sentiment = get_sentiment_score(submission.title)
|
||||||
@@ -63,7 +65,7 @@ def scan_subreddits(reddit, subreddits_list, post_limit=25, comment_limit=100):
|
|||||||
for ticker_symbol in set(tickers_in_post):
|
for ticker_symbol in set(tickers_in_post):
|
||||||
ticker_id = database.get_or_create_entity(conn, 'tickers', 'symbol', ticker_symbol)
|
ticker_id = database.get_or_create_entity(conn, 'tickers', 'symbol', ticker_symbol)
|
||||||
database.add_mention(conn, ticker_id, subreddit_id, submission.id, int(submission.created_utc), post_sentiment)
|
database.add_mention(conn, ticker_id, subreddit_id, submission.id, int(submission.created_utc), post_sentiment)
|
||||||
# (Market cap logic remains the same)
|
|
||||||
ticker_info = database.get_ticker_info(conn, ticker_id)
|
ticker_info = database.get_ticker_info(conn, ticker_id)
|
||||||
current_time = int(time.time())
|
current_time = int(time.time())
|
||||||
if not ticker_info['last_updated'] or (current_time - ticker_info['last_updated'] > MARKET_CAP_REFRESH_INTERVAL):
|
if not ticker_info['last_updated'] or (current_time - ticker_info['last_updated'] > MARKET_CAP_REFRESH_INTERVAL):
|
||||||
@@ -71,27 +73,31 @@ def scan_subreddits(reddit, subreddits_list, post_limit=25, comment_limit=100):
|
|||||||
market_cap = get_market_cap(ticker_symbol)
|
market_cap = get_market_cap(ticker_symbol)
|
||||||
database.update_ticker_market_cap(conn, ticker_id, market_cap or ticker_info['market_cap'])
|
database.update_ticker_market_cap(conn, ticker_id, market_cap or ticker_info['market_cap'])
|
||||||
|
|
||||||
# --- 2. Process the Comments ---
|
# 1b. Process Comments for mentions
|
||||||
# Expand "MoreComments" objects. limit=None means we try to get all, but PRAW is protective.
|
submission.comments.replace_more(limit=0)
|
||||||
# A limit of 32 is the max PRAW will do in a single call. We'll iterate to be safe.
|
for comment in submission.comments.list()[:comment_limit]:
|
||||||
submission.comments.replace_more(limit=10)
|
|
||||||
comment_count = 0
|
|
||||||
for comment in submission.comments.list():
|
|
||||||
if comment_count >= comment_limit:
|
|
||||||
break # Stop processing comments for this post if we hit our limit
|
|
||||||
|
|
||||||
tickers_in_comment = extract_tickers(comment.body)
|
tickers_in_comment = extract_tickers(comment.body)
|
||||||
if not tickers_in_comment:
|
if not tickers_in_comment:
|
||||||
continue # Skip comments that don't mention any tickers
|
continue
|
||||||
|
|
||||||
comment_sentiment = get_sentiment_score(comment.body)
|
comment_sentiment = get_sentiment_score(comment.body)
|
||||||
|
|
||||||
for ticker_symbol in set(tickers_in_comment):
|
for ticker_symbol in set(tickers_in_comment):
|
||||||
ticker_id = database.get_or_create_entity(conn, 'tickers', 'symbol', ticker_symbol)
|
ticker_id = database.get_or_create_entity(conn, 'tickers', 'symbol', ticker_symbol)
|
||||||
# We use the submission.id as the post_id to group mentions correctly
|
|
||||||
database.add_mention(conn, ticker_id, subreddit_id, submission.id, int(comment.created_utc), comment_sentiment)
|
database.add_mention(conn, ticker_id, subreddit_id, submission.id, int(comment.created_utc), comment_sentiment)
|
||||||
|
|
||||||
comment_count += 1
|
# --- LOGIC PART 2: DEEP DIVE ANALYSIS ---
|
||||||
|
all_comment_sentiments = []
|
||||||
|
for comment in submission.comments.list()[:comment_limit]:
|
||||||
|
all_comment_sentiments.append(get_sentiment_score(comment.body))
|
||||||
|
|
||||||
|
avg_sentiment = sum(all_comment_sentiments) / len(all_comment_sentiments) if all_comment_sentiments else 0
|
||||||
|
|
||||||
|
post_analysis_data = {
|
||||||
|
"post_id": submission.id, "title": submission.title,
|
||||||
|
"post_url": f"https://reddit.com{submission.permalink}",
|
||||||
|
"subreddit_id": subreddit_id, "post_timestamp": int(submission.created_utc),
|
||||||
|
"comment_count": len(all_comment_sentiments), "avg_comment_sentiment": avg_sentiment
|
||||||
|
}
|
||||||
|
database.add_or_update_post_analysis(conn, post_analysis_data)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Could not scan r/{subreddit_name}. Error: {e}")
|
print(f"Could not scan r/{subreddit_name}. Error: {e}")
|
||||||
@@ -100,37 +106,13 @@ def scan_subreddits(reddit, subreddits_list, post_limit=25, comment_limit=100):
|
|||||||
print("\n--- Scan Complete ---")
|
print("\n--- Scan Complete ---")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function to run the Reddit stock analysis tool."""
|
parser = argparse.ArgumentParser(description="Analyze stock ticker mentions on Reddit.", formatter_class=argparse.RawTextHelpFormatter)
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description="Analyze stock ticker mentions on Reddit.",
|
|
||||||
formatter_class=argparse.RawTextHelpFormatter # For better help text formatting
|
|
||||||
)
|
|
||||||
|
|
||||||
# --- Existing Argument ---
|
|
||||||
parser.add_argument("config_file", help="Path to the JSON file containing subreddits.")
|
parser.add_argument("config_file", help="Path to the JSON file containing subreddits.")
|
||||||
|
parser.add_argument("-p", "--posts", type=int, default=25, help="Number of posts to scan per subreddit.\n(Default: 25)")
|
||||||
# --- NEW Arguments ---
|
parser.add_argument("-c", "--comments", type=int, default=100, help="Number of comments to scan per post.\n(Default: 100)")
|
||||||
parser.add_argument(
|
parser.add_argument("-l", "--limit", type=int, default=20, help="Number of tickers to show in the final report.\n(Default: 20)")
|
||||||
"-p", "--posts",
|
|
||||||
type=int,
|
|
||||||
default=25,
|
|
||||||
help="Number of posts to scan per subreddit.\n(Default: 25)"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-c", "--comments",
|
|
||||||
type=int,
|
|
||||||
default=100,
|
|
||||||
help="Number of comments to scan per post.\n(Default: 100)"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-l", "--limit",
|
|
||||||
type=int,
|
|
||||||
default=20,
|
|
||||||
help="Number of tickers to show in the final report.\n(Default: 20)"
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# --- Initialize and Run ---
|
|
||||||
database.initialize_db()
|
database.initialize_db()
|
||||||
database.clean_stale_tickers()
|
database.clean_stale_tickers()
|
||||||
|
|
||||||
@@ -140,10 +122,8 @@ def main():
|
|||||||
reddit = get_reddit_instance()
|
reddit = get_reddit_instance()
|
||||||
if not reddit: return
|
if not reddit: return
|
||||||
|
|
||||||
# Pass the command-line arguments to the functions
|
|
||||||
scan_subreddits(reddit, subreddits, post_limit=args.posts, comment_limit=args.comments)
|
scan_subreddits(reddit, subreddits, post_limit=args.posts, comment_limit=args.comments)
|
||||||
database.generate_summary_report(limit=args.limit)
|
database.generate_summary_report(limit=args.limit)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
@@ -5,50 +5,48 @@ import re
|
|||||||
# A set of common English words and acronyms that look like stock tickers.
|
# A set of common English words and acronyms that look like stock tickers.
|
||||||
# This helps reduce false positives.
|
# This helps reduce false positives.
|
||||||
COMMON_WORDS_BLACKLIST = {
|
COMMON_WORDS_BLACKLIST = {
|
||||||
"401K", "403B", "457B", "ABOUT", "ABOVE", "ADAM", "AEDT", "AEST", "AH",
|
"401K", "403B", "457B", "ABOUT", "ABOVE", "ADAM", "AEDT", "AEST", "AH", "AI",
|
||||||
"AI", "ALL", "ALPHA", "ALSO", "AM", "AMA", "AMEX", "AND", "ANY", "AR",
|
"ALL", "ALPHA", "ALSO", "AM", "AMA", "AMEX", "AND", "ANY", "AR", "ARE",
|
||||||
"ARE", "AROUND", "ASAP", "ASS", "ASSET", "AT", "ATH", "ATL", "ATM",
|
"AROUND", "ASAP", "ASS", "ASSET", "AT", "ATH", "ATL", "ATM", "AUD", "BABY",
|
||||||
"AUD", "BE", "BEAR", "BELOW", "BETA", "BIG", "BIS", "BLEND", "BOE",
|
"BAG", "BAGS", "BE", "BEAR", "BELOW", "BETA", "BIG", "BIS", "BLEND", "BOE",
|
||||||
"BOJ", "BOMB", "BOND", "BOTS", "BRB", "BRL", "BS", "BST", "BTC", "BTW",
|
"BOJ", "BOMB", "BOND", "BOTH", "BOTS", "BRB", "BRL", "BS", "BST", "BTC",
|
||||||
"BULL", "BUT", "BUY", "BUZZ", "CAD", "CAN", "CEO", "CEST", "CET", "CFO",
|
"BTW", "BULL", "BUST", "BUT", "BUY", "BUZZ", "CAD", "CALL", "CAN", "CEO",
|
||||||
"CHF", "CIA", "CLOSE", "CNY", "COME", "COST", "COULD", "CPI", "CST",
|
"CEST", "CET", "CFO", "CHF", "CHIPS", "CIA", "CLOSE", "CNY", "COME", "COST",
|
||||||
"CTB", "CTO", "CYCLE", "CZK", "DAO", "DATE", "DAX", "DAY", "DCA", "DD",
|
"COULD", "CPI", "CST", "CTB", "CTO", "CYCLE", "CZK", "DAO", "DATE", "DAX",
|
||||||
"DEBT", "DIA", "DIV", "DJIA", "DKK", "DM", "DO", "DOGE", "DONT", "DR",
|
"DAY", "DCA", "DD", "DEBT", "DIA", "DIV", "DJIA", "DKK", "DM", "DO",
|
||||||
"EACH", "EARLY", "EARN", "ECB", "EDGAR", "EDIT", "EDT", "END", "EPS",
|
"DOE", "DOGE", "DONT", "DR", "EACH", "EARLY", "EARN", "ECB", "EDGAR", "EDIT",
|
||||||
"ER", "ESG", "EST", "ETF", "ETH", "EU", "EUR", "EV", "EVERY", "FAQ",
|
"EDT", "END", "EOD", "EOW", "EOY", "EPS", "ER", "ESG", "EST", "ETF",
|
||||||
"FAR", "FAST", "FBI", "FDA", "FIHTX", "FINRA", "FINT", "FINTX", "FINTY",
|
"ETH", "EU", "EUR", "EV", "EVEN", "EVERY", "FAQ", "FAR", "FAST", "FBI",
|
||||||
"FOMC", "FOMO", "FOR", "FRAUD", "FRG", "FSPSX", "FTSE", "FUCK", "FUD",
|
"FDA", "FIHTX", "FINRA", "FINT", "FINTX", "FINTY", "FOMC", "FOMO", "FOR", "FRAUD",
|
||||||
"FULL", "FUND", "FXAIX", "FXIAX", "FY", "FYI", "FZROX", "GAIN", "GBP",
|
"FRG", "FROM", "FSPSX", "FTSE", "FUCK", "FUD", "FULL", "FUND", "FXAIX", "FXIAX",
|
||||||
"GDP", "GET", "GMT", "GO", "GOAL", "GPU", "GRAB", "GTG", "HAS", "HAVE",
|
"FY", "FYI", "FZROX", "GAIN", "GBP", "GDP", "GET", "GL", "GLHF", "GMT",
|
||||||
"HATE", "HEAR", "HEDGE", "HIGH", "HINT", "HKD", "HODL", "HOLD", "HOUR",
|
"GO", "GOAL", "GOAT", "GOING", "GPU", "GRAB", "GTG", "HALF", "HAS", "HATE",
|
||||||
"HSA", "HUF", "IF", "IMHO", "IMO", "IN", "INR", "IP", "IPO", "IRA",
|
"HAVE", "HEAR", "HEDGE", "HIGH", "HINT", "HKD", "HODL", "HOLD", "HOUR", "HSA",
|
||||||
|
"HUF", "IF", "II", "IMHO", "IMO", "IN", "INR", "IP", "IPO", "IRA",
|
||||||
"IRS", "IS", "ISM", "IST", "IT", "ITM", "IV", "IVV", "IWM", "JPOW",
|
"IRS", "IS", "ISM", "IST", "IT", "ITM", "IV", "IVV", "IWM", "JPOW",
|
||||||
"JPY", "JST", "JUST", "KARMA", "KNOW", "KO", "KRW", "LARGE", "LAST",
|
"JPY", "JST", "JUST", "KARMA", "KEEP", "KNOW", "KO", "KRW", "LARGE", "LAST",
|
||||||
"LATE", "LATER", "LBO", "LEAP", "LEAPS", "LETS", "LFG", "LIKE", "LIMIT",
|
"LATE", "LATER", "LBO", "LEAP", "LEAPS", "LETS", "LFG", "LIKE", "LIMIT", "LMAO",
|
||||||
"LMAO", "LOL", "LONG", "LOOK", "LOSS", "LOVE", "LOW", "M&A", "MAKE",
|
"LOL", "LONG", "LOOK", "LOSS", "LOVE", "LOW", "M&A", "MA", "MAKE", "MAX",
|
||||||
"MAX", "MC", "ME", "MID", "MIGHT", "MIN", "ML", "MOASS", "MONTH", "MSK",
|
"MC", "ME", "MID", "MIGHT", "MIN", "ML", "MOASS", "MONTH", "MORE", "MSK",
|
||||||
"MUST", "MXN", "MY", "NATO", "NEAR", "NEED", "NEVER", "NEW", "NEXT",
|
"MUST", "MXN", "MY", "NATO", "NEAR", "NEED", "NEVER", "NEW", "NEXT", "NFA",
|
||||||
"NFA", "NFT", "NGMI", "NIGHT", "NO", "NOK", "NONE", "NOT", "NOW", "NSA",
|
"NFT", "NGMI", "NIGHT", "NO", "NOK", "NONE", "NOT", "NOW", "NSA", "NULL",
|
||||||
"NULL", "NZD", "NYSE", "OF", "OK", "OLD", "ON", "OP", "OPEN", "OR",
|
"NYSE", "NZD", "OEM", "OF", "OK", "OLD", "ON", "OP", "OR", "OS",
|
||||||
"OTC", "OTM", "OUGHT", "OUT", "OVER", "OWN", "PC", "PDT", "PE", "PEAK",
|
"OTC", "OTM", "OUGHT", "OUT", "OVER", "OWN", "PC", "PDT", "PE", "PEAK",
|
||||||
"PEG", "PEW", "PLAN", "PLN", "PM", "PMI", "POS", "PPI", "PR", "PRICE",
|
"PEG", "PEW", "PLAN", "PLN", "PM", "PMI", "POS", "PPI", "PR", "PRICE",
|
||||||
"PROFIT", "PSA", "PST", "Q1", "Q2", "Q3", "Q4", "QQQ", "RBA", "RBNZ",
|
"PROFIT", "PSA", "PST", "PUT", "Q1", "Q2", "Q3", "Q4", "QQQ", "RBA",
|
||||||
"RE", "REAL", "REIT", "REKT", "RH", "RIP", "RISK", "ROE", "ROFL", "ROI",
|
"RBNZ", "RE", "REAL", "REIT", "REKT", "RH", "RIP", "RISK", "ROE", "ROFL",
|
||||||
"ROTH", "RSD", "RUB", "RULE", "SAVE", "SCALP", "SCAM", "SCHB", "SEC",
|
"ROI", "ROTH", "RSD", "RUB", "RULE", "SAVE", "SCALP", "SCAM", "SCHB", "SEC",
|
||||||
"SEE", "SEK", "SELL", "SEP", "SGD", "SHALL", "SHARE", "SHORT", "SO",
|
"SEE", "SEK", "SELL", "SEP", "SGD", "SHALL", "SHARE", "SHORT", "SL", "SO",
|
||||||
"SOME", "SOON", "SP", "SPAC", "SPEND", "SPLG", "SPX", "SPY", "START",
|
"SOLIS", "SOME", "SOON", "SP", "SPAC", "SPEND", "SPLG", "SPX", "SPY", "START",
|
||||||
"STILL", "STOCK", "STOP", "SWING", "TAKE", "TERM", "THAT", "THE", "THINK",
|
"STILL", "STOCK", "STOP", "SWING", "TAKE", "TERM", "THAT", "THE", "THINK", "THIS",
|
||||||
"THIS", "TIME", "TITS", "TL", "TL;DR", "TLDR", "TO", "TODAY", "TOTAL",
|
"TIME", "TITS", "TL", "TL;DR", "TLDR", "TO", "TODAY", "TOTAL", "TRADE", "TREND",
|
||||||
"TRADE", "TREND", "TRUE", "TRY", "TTYL", "TWO", "UI", "UK", "UNDER",
|
"TRUE", "TRY", "TTYL", "TWO", "UI", "UK", "UNDER", "UP", "US", "USA",
|
||||||
"UP", "US", "USA", "USD", "UTC", "VTI", "VALUE", "VOO", "VR", "WAGMI",
|
"USD", "UTC", "VALUE", "VOO", "VR", "VTI", "WAGMI", "WANT", "WATCH", "WAY",
|
||||||
"WANT", "WATCH", "WAY", "WE", "WEB3", "WEEK", "WHO", "WHY", "WILL",
|
"WE", "WEB3", "WEEK", "WHO", "WHY", "WILL", "WORTH", "WOULD", "WSB", "WTF",
|
||||||
"WORTH", "WOULD", "WSB", "WTF", "YET", "YIELD", "YES", "YOLO", "YOU",
|
"YES", "YET", "YIELD", "YOLO", "YOU", "YOUR", "YTD", "ZAR"
|
||||||
"ZAR",
|
|
||||||
"YOUR", "BABY", "BAG", "BAGS", "GL", "GLHF", "EOD", "EOW", "EOY", "GOING", "KEEP",
|
|
||||||
"MORE", "PUT", "CALL", "YTD", "BOTH", "BUST", "EVEN", "FROM", "GOAT", "HALF",
|
|
||||||
"SL", "OS", "SOLIS", "OEM", "MA", "DOE", "II", "CHIPS"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def extract_tickers(text):
|
def extract_tickers(text):
|
||||||
"""
|
"""
|
||||||
Extracts potential stock tickers from a given piece of text.
|
Extracts potential stock tickers from a given piece of text.
|
||||||
|
@@ -71,6 +71,28 @@
|
|||||||
.sentiment-bullish { color: #28a745; font-weight: 600; }
|
.sentiment-bullish { color: #28a745; font-weight: 600; }
|
||||||
.sentiment-bearish { color: #dc3545; font-weight: 600; }
|
.sentiment-bearish { color: #dc3545; font-weight: 600; }
|
||||||
.sentiment-neutral { color: #6c757d; }
|
.sentiment-neutral { color: #6c757d; }
|
||||||
|
|
||||||
|
.post-card {
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
.post-card h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
.post-card h3 a {
|
||||||
|
color: #0056b3;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.post-card h3 a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.post-meta {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
29
templates/deep_dive.html
Normal file
29
templates/deep_dive.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Deep Dive: {{ symbol }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Deep Dive Analysis for: <strong>{{ symbol }}</strong></h1>
|
||||||
|
<p>Showing posts that mention {{ symbol }}, sorted by most recent.</p>
|
||||||
|
|
||||||
|
{% for post in posts %}
|
||||||
|
<div class="post-card">
|
||||||
|
<h3><a href="{{ post.post_url }}" target="_blank">{{ post.title }}</a></h3>
|
||||||
|
<div class="post-meta">
|
||||||
|
<span>r/{{ post.subreddit_name }}</span> |
|
||||||
|
<span>{{ post.comment_count }} comments analyzed</span> |
|
||||||
|
<span>Avg. Sentiment:
|
||||||
|
{% if post.avg_comment_sentiment > 0.1 %}
|
||||||
|
<span class="sentiment-bullish">{{ "%.2f"|format(post.avg_comment_sentiment) }}</span>
|
||||||
|
{% elif post.avg_comment_sentiment < -0.1 %}
|
||||||
|
<span class="sentiment-bearish">{{ "%.2f"|format(post.avg_comment_sentiment) }}</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="sentiment-neutral">{{ "%.2f"|format(post.avg_comment_sentiment) }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p>No analyzed posts found for this ticker. Run the 'rstat' scraper to gather data.</p>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
@@ -16,7 +16,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for ticker in tickers %}
|
{% for ticker in tickers %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>{{ ticker.symbol }}</strong></td>
|
<td><strong><a href="/deep-dive/{{ ticker.symbol }}">{{ ticker.symbol }}</a></strong></td>
|
||||||
<td>{{ ticker.mention_count }}</td>
|
<td>{{ ticker.mention_count }}</td>
|
||||||
<td>{{ ticker.market_cap | format_mc }}</td>
|
<td>{{ ticker.market_cap | format_mc }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for ticker in tickers %}
|
{% for ticker in tickers %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>{{ ticker.symbol }}</strong></td>
|
<td><strong><a href="/deep-dive/{{ ticker.symbol }}">{{ ticker.symbol }}</a></strong></td>
|
||||||
<td>{{ ticker.mention_count }}</td>
|
<td>{{ ticker.mention_count }}</td>
|
||||||
<td>{{ ticker.market_cap | format_mc }}</td>
|
<td>{{ ticker.market_cap | format_mc }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
Reference in New Issue
Block a user