1
0
mirror of https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git synced 2025-06-16 15:17:29 +00:00

Stock now uses only one api call for unlimited number of tickers

This commit is contained in:
Anson 2019-01-08 18:09:24 -07:00
parent 45a80a0b76
commit 549cd9ba6d

View File

@ -29,19 +29,19 @@ async def on_message(message):
channel = message.channel channel = message.channel
tickers = re.findall('[$](\w{1,4})', content) tickers = re.findall('[$](\w{1,4})', content)
print(tickers) print(tickers)
for ticker in tickers: url = 'https://data.bravos.co/v1/quote?symbols=' + ",".join(tickers) + \
print(ticker)
url = 'https://data.bravos.co/v1/quote?symbols=' + ticker + \
'&apikey=' + BRAVOS_API + '&format=json' '&apikey=' + BRAVOS_API + '&format=json'
print(url) print(url)
with urllib.request.urlopen(url) as url: with urllib.request.urlopen(url) as url:
data = json.loads(url.read().decode()) data = json.loads(url.read().decode())
for ticker in tickers:
try:
nameTicker = data[ticker.upper()]['name'] nameTicker = data[ticker.upper()]['name']
print(nameTicker)
priceTicker = data[ticker.upper()]['price'] priceTicker = data[ticker.upper()]['price']
print(str(priceTicker))
await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $' + str(priceTicker)) await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $' + str(priceTicker))
except KeyError:
await client.send_message(channel, ticker.upper() + ' does not exist.')
pass
async def list_servers(): async def list_servers():