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) '&apikey=' + BRAVOS_API + '&format=json'
url = 'https://data.bravos.co/v1/quote?symbols=' + ticker + \ print(url)
'&apikey=' + BRAVOS_API + '&format=json' with urllib.request.urlopen(url) as url:
print(url) data = json.loads(url.read().decode())
for ticker in tickers:
with urllib.request.urlopen(url) as url: try:
data = json.loads(url.read().decode()) nameTicker = data[ticker.upper()]['name']
nameTicker = data[ticker.upper()]['name'] priceTicker = data[ticker.upper()]['price']
print(nameTicker) await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $' + str(priceTicker))
priceTicker = data[ticker.upper()]['price'] except KeyError:
print(str(priceTicker)) await client.send_message(channel, ticker.upper() + ' does not exist.')
await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $' + str(priceTicker)) pass
async def list_servers(): async def list_servers():