Yay stock now returns a color coded embed object
This commit is contained in:
parent
6b56ee71ae
commit
8e1d31b8d7
@ -305,7 +305,7 @@ async def on_message(message):
|
|||||||
if message.content.startswith('!stock'):
|
if message.content.startswith('!stock'):
|
||||||
await client.send_message(
|
await client.send_message(
|
||||||
message.channel,
|
message.channel,
|
||||||
stock.parse_share(message.content)
|
embed=stock.parse_share(message.content)
|
||||||
)
|
)
|
||||||
|
|
||||||
if message.content.startswith('!pout'):
|
if message.content.startswith('!pout'):
|
||||||
|
29
app/stock.py
29
app/stock.py
@ -1,12 +1,13 @@
|
|||||||
import requests
|
import discord
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
def parse_share(msg):
|
def parse_share(msg):
|
||||||
if len(msg.split()) > 1:
|
if len(msg.split()) > 1:
|
||||||
try:
|
try:
|
||||||
res = ''
|
res = ''
|
||||||
for s in msg.split()[1:]:
|
for s in msg.split()[1:]:
|
||||||
res = '{}\n\n{}'.format(res, get_stock(s))
|
res = get_stock(s)
|
||||||
except:
|
except:
|
||||||
res = '```Please input valid shares: !stock [share_name]```'
|
res = '```Please input valid shares: !stock [share_name]```'
|
||||||
return res
|
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_string = "https://fmpcloud.io/api/v3/quote/%s?apikey=%s" % (share_name, token)
|
||||||
request = requests.get(request_string).json()[0]
|
request = requests.get(request_string).json()[0]
|
||||||
|
|
||||||
previous_close = request['previousClose']
|
change_symbol = '+'
|
||||||
opening_price = request['open']
|
embed_color = 2067276
|
||||||
current_price = request['price']
|
if float(request['price']) < float(request['open']):
|
||||||
change = request['change']
|
change_symbol = '-'
|
||||||
day_low = request['dayLow']
|
embed_color = 15158332
|
||||||
day_high = request['dayHigh']
|
|
||||||
|
|
||||||
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