From dcf1abd1cffca1c90f53752e78570e4a38c85400 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 8 Jan 2019 16:50:45 -0700 Subject: [PATCH] init commit --- credentials.py | 4 ++++ requirements.txt | 2 ++ stockBot.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 credentials.py create mode 100644 requirements.txt create mode 100644 stockBot.py diff --git a/credentials.py b/credentials.py new file mode 100644 index 0000000..60f8309 --- /dev/null +++ b/credentials.py @@ -0,0 +1,4 @@ +secrets = { + 'TOKEN': "https://discordapp.com/developers/applications/ > BOTNAME > Bot > 'copy token'", + 'BRAVOS_API': 'https://bravos.co/a/login' +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0fe1883 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +discord.py==0.16.12 +discord==0.0.2 diff --git a/stockBot.py b/stockBot.py new file mode 100644 index 0000000..d44d61a --- /dev/null +++ b/stockBot.py @@ -0,0 +1,50 @@ +# Work with Python 3.6 +import json +from discord.ext import commands +import discord +import re +import urllib.request +import credentials + +BOT_PREFIX = ("?", "!") +TOKEN = credentials.secrets['TOKEN'] +BRAVOS_API = credentials.secrets['BRAVOS_API'] + +client = commands.Bot(command_prefix=BOT_PREFIX) + + +@client.event +async def on_ready(): + print('Bot is Ready!!!') + + +@client.event +async def on_message(message): + author = message.author + content = message.content + channel = message.channel + tickers = re.findall('[$](\w{1,4})', content) + print(tickers) + for ticker in tickers: + print(ticker) + url = 'https://data.bravos.co/v1/quote?symbols=' + ticker + \ + '&apikey=' + BRAVOS_API + '&format=json' + print(url) + + with urllib.request.urlopen(url) as url: + data = json.loads(url.read().decode()) + nameTicker = data[ticker.upper()]['name'] + print(nameTicker) + priceTicker = data[ticker.upper()]['price'] + print(str(priceTicker)) + await client.send_message(channel, 'The current stock price of ' + nameTicker + ' is $' + str(priceTicker)) + + +async def list_servers(): + await client.wait_until_ready() + while not client.is_closed: + print("Current servers:") + for server in client.servers: + print(server.name) + +client.run(TOKEN)