Skip to content

Instantly share code, notes, and snippets.

@invisiblek
Created March 12, 2021 15:54
Show Gist options
  • Save invisiblek/85c3f5b4dabeac37ef9e1388d48852c6 to your computer and use it in GitHub Desktop.
Save invisiblek/85c3f5b4dabeac37ef9e1388d48852c6 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