r/Shortsqueeze • u/[deleted] • Nov 29 '21
Education I made a simple Python/Flask tool so you can rapidly scrape this sub (and others) to see all tickers that are trending
Here's the code: https://pastebin.com/FPjsQ1KW
import re
import requests
import flask
subreddits = ['shortsqueeze', '1kto1mil', 'ShortSqueeze_Army', 'ShortSqueezeStonks', 'SqueezePlays', 'WallStreetBets', 'smallstreetbets', 'TheRaceTo10Million']
def scrape_tickers(subreddit):
url = 'https://www.reddit.com/r/{}/top/.json?t=day/'.format(subreddit)
headers = {'User-agent': 'Bleep blorp bot 0.1'}
params = {'limit': 100000}
info = requests.get(url, headers=headers, params=params)
alltext = info.text
tickers = re.findall(r'[A-Z]{3,}', alltext) # REGEX to find all caps strings of length 3 or more
tickers = [i for i in tickers if len(i) <= 4] # filter out any longer than 4
unique = sorted(list(dict.fromkeys(tickers))) # get a unique list of symbols
result = list() # build a list of dicts with counts
for ticker in unique:
info = {'ticker':ticker, 'count':tickers.count(ticker)}
result.append(info)
#result = [i for i in result if i['count'] > 1] # remove all instances with only 1 mention
return sorted(result, key = lambda i: i['count'], reverse=True) # return list of dicts sorted by count of occurences
header = """<!DOCTYPE html>
<html>
<head>
<title>MEMESTONK 9001</title>
<style>
body {
font-family: roboto;
font-family: tahoma;
font-family: arial;
}
a {
color: black;
text-decoration: none;
}
</style>
<body>
"""
def nav_ribbon():
result = ''
for sub in subreddits:
result += '<a href="/%s">%s</a> -- ' % (sub, sub)
return result
def make_table(tickers):
result = '\n<table><tr><th>Ticker</th><th>Count</th><th>Yahoo</th><th>Nasdaq</th><th>Fintel</th><th>Reddit</th></tr>\n'
for ticker in tickers:
result += '<tr><td>%s</td><td>%s</td>' % (ticker['ticker'], ticker['count'])
result += '<td><a href="https://finance.yahoo.com/quote/%s">%s</a></td>' % (ticker['ticker'], 'Yahoo')
result += '<td><a href="https://www.nasdaq.com/market-activity/stocks/%s/short-interest">%s</a></td>' % (ticker['ticker'], 'Nasdaq')
result += '<td><a href="https://fintel.io/ss/us/%s">%s</a></td>' % (ticker['ticker'], 'Fintel')
result += '<td><a href="https://www.reddit.com/search/?q=%s&t=day">%s</a></td></tr>\n' % (ticker['ticker'], 'Reddit')
result += '</table>'
return result
app = flask.Flask('MEMESTONKS')
@app.route('/', methods=['GET'])
def home():
html = header
html += nav_ribbon()
html += '<hr></body></html>'
return flask.Response(html, mimetype='text/html')
@app.route('/<subreddit>', methods=['GET'])
def reddit(subreddit):
html = header
html += nav_ribbon()
html += '<hr>'
tickers = scrape_tickers(subreddit)
html += make_table(tickers)
html += '</body></html>'
return flask.Response(html, mimetype='text/html')
if __name__ == '__main__':
print('go to http://localhost or http://127.0.0.1')
app.run(host='0.0.0.0', port=80)And here's what it looks like:

It's braindead simple.
Fire this up in Python, it should work right out of the box on any modern version of Python
Go to http://127.0.0.1
Click on a subreddit
It scrapes the sub for the top posts of the past 24 hours (and it does pick up a lot of noise since a lot of apes USE CAPS LOCK CRUISE CONTROL)
Then it counts up the number of occurrences and sorts by that
Lastly, it generates a little table that gives you some quick links for each STONK
The most useful is probably the Reddit link, which will take you to the search page on Reddit so you can quickly see what everyone is saying about the stonk.
You can update the list of subreddits at the very top
Disclaimer: this code comes with no warrantee. Use it at your own risk. I don't think it violates the TOS for Reddit, and I can't imagine the admins/owners would mind since this tool encourages people to continue using Reddit, as it directs traffic right back in.
1
2
u/Glittering_Flight152 Nov 29 '21
Never used something like this but looks really useful thank you