Improved logging and added option for --stdout.
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
import sqlite3
|
||||
import time
|
||||
from .ticker_extractor import COMMON_WORDS_BLACKLIST
|
||||
from .logger_setup import get_logger
|
||||
from .logger_setup import logger as log
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
DB_FILE = "reddit_stocks.db"
|
||||
log = get_logger()
|
||||
|
||||
def get_db_connection():
|
||||
"""Establishes a connection to the SQLite database."""
|
||||
@@ -251,52 +250,6 @@ def get_week_start_end(for_date):
|
||||
|
||||
return start_of_week, end_of_week
|
||||
|
||||
def generate_summary_report(limit=20):
|
||||
"""Queries the DB to generate a summary for the command-line tool."""
|
||||
log.info(f"\n--- Top {limit} Tickers by Mention Count ---")
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# --- UPDATED QUERY: Changed m.sentiment_score to m.mention_sentiment ---
|
||||
query = """
|
||||
SELECT
|
||||
t.symbol, t.market_cap, t.closing_price,
|
||||
COUNT(m.id) as mention_count,
|
||||
SUM(CASE WHEN m.mention_sentiment > 0.1 THEN 1 ELSE 0 END) as bullish_mentions,
|
||||
SUM(CASE WHEN m.mention_sentiment < -0.1 THEN 1 ELSE 0 END) as bearish_mentions,
|
||||
SUM(CASE WHEN m.mention_sentiment BETWEEN -0.1 AND 0.1 THEN 1 ELSE 0 END) as neutral_mentions
|
||||
FROM mentions m JOIN tickers t ON m.ticker_id = t.id
|
||||
GROUP BY t.symbol, t.market_cap, t.closing_price
|
||||
ORDER BY mention_count DESC
|
||||
LIMIT ?;
|
||||
"""
|
||||
results = cursor.execute(query, (limit,)).fetchall()
|
||||
|
||||
header = f"{'Ticker':<8} | {'Mentions':<8} | {'Bullish':<8} | {'Bearish':<8} | {'Neutral':<8} | {'Market Cap':<15} | {'Close Price':<12}"
|
||||
print(header)
|
||||
print("-" * (len(header) + 2)) # Adjusted separator length
|
||||
|
||||
for row in results:
|
||||
market_cap_str = "N/A"
|
||||
if row['market_cap'] and row['market_cap'] > 0:
|
||||
mc = row['market_cap']
|
||||
if mc >= 1e12: market_cap_str = f"${mc/1e12:.2f}T"
|
||||
elif mc >= 1e9: market_cap_str = f"${mc/1e9:.2f}B"
|
||||
else: market_cap_str = f"${mc/1e6:.2f}M"
|
||||
|
||||
closing_price_str = f"${row['closing_price']:.2f}" if row['closing_price'] else "N/A"
|
||||
|
||||
print(
|
||||
f"{row['symbol']:<8} | "
|
||||
f"{row['mention_count']:<8} | "
|
||||
f"{row['bullish_mentions']:<8} | "
|
||||
f"{row['bearish_mentions']:<8} | "
|
||||
f"{row['neutral_mentions']:<8} | "
|
||||
f"{market_cap_str:<15} | "
|
||||
f"{closing_price_str:<12}"
|
||||
)
|
||||
conn.close()
|
||||
|
||||
def add_or_update_post_analysis(conn, post_data):
|
||||
"""
|
||||
Inserts a new post analysis record or updates an existing one.
|
||||
|
Reference in New Issue
Block a user