commit 7feeba008b025bce1769f8224367052ad7168592 Author: Wesley Kerfoot Date: Tue Jan 26 04:32:49 2021 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84bfd65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +venv +.envrc diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..2668588 --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +python -m wsbfin.wsbfin diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e6d80f8 --- /dev/null +++ b/setup.py @@ -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" + ] + } +) diff --git a/wsbfin/wsbfin.py b/wsbfin/wsbfin.py new file mode 100644 index 0000000..f5e1865 --- /dev/null +++ b/wsbfin/wsbfin.py @@ -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)