stock plugin mk1
This commit is contained in:
parent
ad3ebc5a7c
commit
5a711b34d5
@ -4,7 +4,7 @@ services:
|
||||
|
||||
before_script:
|
||||
- apk add --no-cache python3
|
||||
- pip3 install pylint requests discord.py docker pylint wolframalpha pyowm beautifulsoup4
|
||||
- pip3 install pylint requests discord.py docker pylint wolframalpha pyowm beautifulsoup4 yahoo-finance
|
||||
|
||||
stages:
|
||||
- test
|
||||
|
@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6
|
||||
LABEL name="Dragon Bot"
|
||||
RUN apk update && apk add --no-cache docker
|
||||
|
||||
RUN pip install requests discord.py docker wolframalpha pyowm beautifulsoup4
|
||||
RUN pip install requests discord.py docker wolframalpha pyowm beautifulsoup4 yahoo-finance
|
||||
ADD app /app
|
||||
|
||||
CMD python app/dragon-bot.py
|
||||
|
@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6
|
||||
LABEL name="Dragon Bot Test environment"
|
||||
RUN apk update && apk add --no-cache vim docker
|
||||
|
||||
RUN pip install requests discord.py docker pylint wolframalpha pyowm beautifulsoup4
|
||||
RUN pip install requests discord.py docker pylint wolframalpha pyowm beautifulsoup4 yahoo-finance
|
||||
ADD app /app
|
||||
|
||||
RUN printf "\n\nTesting your python code for errors\n\n" && \
|
||||
|
@ -22,6 +22,7 @@ import role_check
|
||||
import wallpaper
|
||||
import weather
|
||||
import wolfram
|
||||
import stock
|
||||
|
||||
# Client object
|
||||
client = discord.Client()
|
||||
@ -121,7 +122,13 @@ async def on_message(message):
|
||||
if message.content.startswith('!weather'):
|
||||
await client.send_message(
|
||||
message.channel,
|
||||
weather.get_weather(message.content)
|
||||
weather.parse_loc(message.content)
|
||||
)
|
||||
|
||||
if message.content.startswith('!stock'):
|
||||
await client.send_message(
|
||||
message.channel,
|
||||
stock.parse_share(message.content)
|
||||
)
|
||||
|
||||
if message.content.startswith('!pout'):
|
||||
|
21
app/stock.py
Normal file
21
app/stock.py
Normal file
@ -0,0 +1,21 @@
|
||||
import yahoo_finance
|
||||
|
||||
def parse_share(msg):
|
||||
if len(msg.split()) > 1:
|
||||
print(msg.split()[1:])
|
||||
try:
|
||||
res = ''
|
||||
for s in msg.split()[1:]:
|
||||
res = '{}\n\n{}'.format(res, get_stock(s))
|
||||
except yahoo_finance.YQLResponseMalformedError:
|
||||
res = '```Please input valid shares: !stock [share_name]```'
|
||||
return res
|
||||
return '```Please input at least one valid share: !stock [share_name]```'
|
||||
|
||||
def get_stock(share_name):
|
||||
share = yahoo_finance.Share(share_name)
|
||||
open_price = share.get_open()
|
||||
curr_price = share.get_price()
|
||||
change = curr_price - open_price
|
||||
return '```Stock: {}\n\nOpen: ${}\nCurrently: ${}\nChange:```'.format(
|
||||
share_name.upper(), open_price, curr_price)
|
Loading…
x
Reference in New Issue
Block a user