From 1540401f56fd0b013bb53834e30068f1ca260dc4 Mon Sep 17 00:00:00 2001 From: ein Date: Tue, 13 Jul 2021 21:23:35 -0700 Subject: [PATCH] fixing the stock function, it needs a fake user agent now --- app/stock.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/stock.py b/app/stock.py index 753fea8b..f8c262ac 100644 --- a/app/stock.py +++ b/app/stock.py @@ -16,12 +16,15 @@ def parse_message(msg): def get_stock(share_name): share_name = share_name.upper() + # Fake headers to make yahoo happy + headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'} request_string = "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US®ion=US&corsDomain=finance.yahoo.com&symbols=%s" % share_name - request = requests.get(request_string).json()['quoteResponse']['result'][0] + request = requests.get(request_string, headers=headers).json()['quoteResponse']['result'][0] change_symbol = '+' embed_color = 2067276 meme_url = 'https://i.ytimg.com/vi/if-2M3K1tqk/hqdefault.jpg' + # If stock price has gone down since open, use red and a sad stonk meme if float(request['bid']) < float(request['regularMarketOpen']): change_symbol = '-' embed_color = 15158332