Fix /stock timeouts
This commit is contained in:
parent
abaf678577
commit
6eac04c67f
@ -190,9 +190,8 @@ class ActualUtils(commands.Cog):
|
|||||||
|
|
||||||
results = stock.parse_message(symbols, verbose)
|
results = stock.parse_message(symbols, verbose)
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
original_message = await ctx.followup.send("Standby")
|
|
||||||
for res in results:
|
for res in results:
|
||||||
await original_message.edit(content="", embed=res)
|
await ctx.respond(embed=res)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
16
app/stock.py
16
app/stock.py
@ -94,8 +94,8 @@ def get_stock(share_name, verbose=False):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = yf.Ticker(share_name).info
|
request = yf.Ticker(share_name).fast_info
|
||||||
except requests.exceptions.HTTPError:
|
except Exception as e:
|
||||||
raise ValueError("Invalid symbol %s: empty response from Yahoo" % share_name)
|
raise ValueError("Invalid symbol %s: empty response from Yahoo" % share_name)
|
||||||
|
|
||||||
change_symbol = "+"
|
change_symbol = "+"
|
||||||
@ -103,7 +103,7 @@ def get_stock(share_name, verbose=False):
|
|||||||
meme_url = "https://i.ytimg.com/vi/if-2M3K1tqk/hqdefault.jpg"
|
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 stock price has gone down since open, use red and a sad stonk meme
|
||||||
|
|
||||||
current_change = request["currentPrice"] - request["regularMarketOpen"]
|
current_change = request["lastPrice"] - request["open"]
|
||||||
if current_change < 0:
|
if current_change < 0:
|
||||||
change_symbol = "-"
|
change_symbol = "-"
|
||||||
embed_color = 15158332
|
embed_color = 15158332
|
||||||
@ -111,17 +111,17 @@ def get_stock(share_name, verbose=False):
|
|||||||
|
|
||||||
embed = discord.Embed(description="-------", color=embed_color, type="rich")
|
embed = discord.Embed(description="-------", color=embed_color, type="rich")
|
||||||
embed.set_thumbnail(url=meme_url)
|
embed.set_thumbnail(url=meme_url)
|
||||||
embed.set_author(name=request["shortName"])
|
embed.set_author(name=share_name)
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Current price",
|
name="Current price",
|
||||||
value="$%s" % request["currentPrice"],
|
value="$" + format(request["lastPrice"], ",.2f"),
|
||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Opening price",
|
name="Opening price",
|
||||||
value="$%s" % request["regularMarketOpen"],
|
value="$" + format(request["open"], ",.2f"),
|
||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
@ -129,7 +129,7 @@ def get_stock(share_name, verbose=False):
|
|||||||
value="$%.2f (%.7f%%)"
|
value="$%.2f (%.7f%%)"
|
||||||
% (
|
% (
|
||||||
current_change,
|
current_change,
|
||||||
current_change * 100 / request["regularMarketOpen"],
|
current_change * 100 / request["open"],
|
||||||
),
|
),
|
||||||
inline=False,
|
inline=False,
|
||||||
)
|
)
|
||||||
@ -140,7 +140,7 @@ def get_stock(share_name, verbose=False):
|
|||||||
chart_url = "https://www.marketwatch.com/investing/stock"
|
chart_url = "https://www.marketwatch.com/investing/stock"
|
||||||
if "-" in share_name:
|
if "-" in share_name:
|
||||||
chart_url = "https://coinmarketcap.com/currencies"
|
chart_url = "https://coinmarketcap.com/currencies"
|
||||||
share_name = request["shortName"].split()[0].lower()
|
share_name = share_name.split()[0].lower()
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Link to stock price",
|
name="Link to stock price",
|
||||||
value="%s/%s" % (chart_url, share_name),
|
value="%s/%s" % (chart_url, share_name),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user