Yay stock now returns a color coded embed object
This commit is contained in:
parent
317334798a
commit
5a3f5fcb21
@ -305,7 +305,7 @@ async def on_message(message):
|
||||
if message.content.startswith('!stock'):
|
||||
await client.send_message(
|
||||
message.channel,
|
||||
stock.parse_share(message.content)
|
||||
embed=stock.parse_share(message.content)
|
||||
)
|
||||
|
||||
if message.content.startswith('!pout'):
|
||||
|
29
app/stock.py
29
app/stock.py
@ -1,12 +1,13 @@
|
||||
import requests
|
||||
import discord
|
||||
import os
|
||||
import requests
|
||||
|
||||
def parse_share(msg):
|
||||
if len(msg.split()) > 1:
|
||||
try:
|
||||
res = ''
|
||||
for s in msg.split()[1:]:
|
||||
res = '{}\n\n{}'.format(res, get_stock(s))
|
||||
res = get_stock(s)
|
||||
except:
|
||||
res = '```Please input valid shares: !stock [share_name]```'
|
||||
return res
|
||||
@ -19,11 +20,21 @@ def get_stock(share_name):
|
||||
request_string = "https://fmpcloud.io/api/v3/quote/%s?apikey=%s" % (share_name, token)
|
||||
request = requests.get(request_string).json()[0]
|
||||
|
||||
previous_close = request['previousClose']
|
||||
opening_price = request['open']
|
||||
current_price = request['price']
|
||||
change = request['change']
|
||||
day_low = request['dayLow']
|
||||
day_high = request['dayHigh']
|
||||
change_symbol = '+'
|
||||
embed_color = 2067276
|
||||
if float(request['price']) < float(request['open']):
|
||||
change_symbol = '-'
|
||||
embed_color = 15158332
|
||||
|
||||
return "```Current price: $%s\nOpen: $%s\nPrevious close: $%s\nChange: $%s\nDay low: $%s\nDay High: $%s```" % (current_price, opening_price, previous_close, change, day_low, day_high)
|
||||
embed = discord.Embed(description='Stock info', color=embed_color, type="rich")
|
||||
embed.set_author(name=request['name'])
|
||||
embed.add_field(name='Current Price', value=request['price'], inline=False)
|
||||
embed.add_field(name='Previous Close', value=request['previousClose'], inline=False)
|
||||
embed.add_field(name='Opening price', value=request['open'], inline=False)
|
||||
embed.add_field(name='Change', value="%s $%s" % (change_symbol, request['change']), inline=False)
|
||||
embed.add_field(name='Change percent', value="%s %s%%" % (change_symbol, request['changesPercentage']), inline=False)
|
||||
embed.add_field(name='Day Low', value=request['dayLow'], inline=False)
|
||||
embed.add_field(name='Day High', value=request['dayHigh'], inline=False)
|
||||
embed.set_footer(text="Pulled from https://fmpcloud.io", icon_url='https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/emojidex/112/chart-with-downwards-trend_1f4c9.png')
|
||||
|
||||
return embed
|
Loading…
x
Reference in New Issue
Block a user