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:
parent
45a80a0b76
commit
549cd9ba6d
12
stockBot.py
12
stockBot.py
@ -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():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user