commit
7feeba008b
5 changed files with 100 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||
|
__pycache__ |
||||
|
venv |
||||
|
.envrc |
@ -0,0 +1,2 @@ |
|||||
|
#! /usr/bin/env bash |
||||
|
python -m wsbfin.wsbfin |
@ -0,0 +1,32 @@ |
|||||
|
import setuptools |
||||
|
|
||||
|
with open("README.md", "r") as fh: |
||||
|
long_description = fh.read() |
||||
|
|
||||
|
setuptools.setup( |
||||
|
name="wsbfin", |
||||
|
version="1.0.0", |
||||
|
author="Wesley Kerfoot", |
||||
|
author_email="wes@wesk.tech", |
||||
|
description="A tool to track stock symbols mentioned", |
||||
|
long_description=long_description, |
||||
|
long_description_content_type="text/markdown", |
||||
|
url="https://github.com/weskerfoot/wsbfin", |
||||
|
packages=setuptools.find_packages(), |
||||
|
include_package_data=True, |
||||
|
requires_python=">=3.7", |
||||
|
install_requires = [ |
||||
|
"yahoo-finance", |
||||
|
"praw" |
||||
|
], |
||||
|
classifiers= [ |
||||
|
"Programming Language :: Python :: 3", |
||||
|
"License :: OSI Approved :: MIT License", |
||||
|
"Operating System :: OS Independent", |
||||
|
], |
||||
|
entry_points = { |
||||
|
"console_scripts" : [ |
||||
|
"wsbfin = wsbfin.wsbfin:main" |
||||
|
] |
||||
|
} |
||||
|
) |
@ -0,0 +1,63 @@ |
|||||
|
import praw |
||||
|
import yfinance as yf |
||||
|
from os import environ |
||||
|
from collections import defaultdict |
||||
|
from queue import Queue as queue |
||||
|
from re import search |
||||
|
|
||||
|
reddit = praw.Reddit(client_id=environ.get("CLIENT_ID"), |
||||
|
client_secret=environ.get("SECRET"), |
||||
|
password=environ.get("PASSWORD"), |
||||
|
user_agent="testscript by u/weskerfoot", |
||||
|
username="weskerfoot") |
||||
|
|
||||
|
|
||||
|
ignored = {"DD", "USA", "USA", "WBS", "FD"} |
||||
|
symbols = defaultdict(int) |
||||
|
|
||||
|
def normalize_symbol(text): |
||||
|
""" |
||||
|
Try to extract a stock symbol from a word, and return it. |
||||
|
""" |
||||
|
result = search(r"\$?[A-Z]{2,5}", text) or search(r"\$[A-Z]{2,5}", text) |
||||
|
if result and result.group(0).upper() in symbols: |
||||
|
sym = result.group(0).upper() |
||||
|
|
||||
|
if sym.startswith("$"): |
||||
|
sym = sym[1:] |
||||
|
|
||||
|
symbols[sym] += 1 |
||||
|
return |
||||
|
|
||||
|
if result: |
||||
|
sym = result.group(0).upper() |
||||
|
if sym in ignored and (not sym.startswith("$")): |
||||
|
return None |
||||
|
|
||||
|
if sym.startswith("$"): |
||||
|
sym = sym[1:] |
||||
|
|
||||
|
try: |
||||
|
yf.Ticker(sym).info # it's a real symbol |
||||
|
symbols[sym] += 1 |
||||
|
except: |
||||
|
pass |
||||
|
return None |
||||
|
|
||||
|
# use bloom filter to skip seen submissions/comments/etc |
||||
|
# store everything in database, store bloom filter in the database too |
||||
|
|
||||
|
# get stock symbol mentioned in comment -> count number of replies, use that to weight them |
||||
|
# store raw numbers for current day, after current day has elapsed, compress it into one row as array of most mentioned stocks in sorted order |
||||
|
|
||||
|
def submissions(sr): |
||||
|
for submission in reddit.subreddit(sr).stream.submissions(): |
||||
|
for comment in submission.comments: |
||||
|
if not hasattr(comment, "replies"): |
||||
|
continue |
||||
|
for reply in comment.replies: |
||||
|
if hasattr(reply, "body"): |
||||
|
yield normalize_symbol(reply.body) |
||||
|
|
||||
|
for comment in submissions("wallstreetbets"): |
||||
|
print(symbols) |
Loading…
Reference in new issue