Skip to content

Instantly share code, notes, and snippets.

@invisiblek
Created March 12, 2021 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invisiblek/df7d59067efe7f8cc1516f2c1bba1b5c to your computer and use it in GitHub Desktop.
Save invisiblek/df7d59067efe7f8cc1516f2c1bba1b5c to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import json
import os
import requests
import sys
import yfinance
s = sys.argv[1]
threshold = float(sys.argv[2])
force = False
if len(sys.argv) > 3 and sys.argv[3] == "force":
force = True
# insert discord webhook url here
url = ""
bid = yfinance.Ticker(sys.argv[1]).info['bid']
stocks = {}
if os.path.exists('/home/dp/stocker.json'):
with open('/home/dp/stocker.json') as j:
stocks = json.load(j)
if s in stocks:
check_threshold = 0
while check_threshold < bid or check_threshold < stocks[s]:
if force or (check_threshold > bid and check_threshold < stocks[s]) or (check_threshold < bid and check_threshold > stocks[s]):
msg = "Price for {} has hit {}".format(s, bid)
print(msg)
data = {
"content" : msg,
"username" : "stonkbot"
}
#requests.post(url, json=data)
break
else:
check_threshold = check_threshold + threshold
stocks[s] = bid
with open('/home/dp/stocker.json', 'w') as j:
json.dump(stocks, j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment