stock plugin mk1

This commit is contained in:
Jason Ji 2017-09-24 17:31:03 -07:00
parent ad3ebc5a7c
commit 5a711b34d5
5 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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" && \

View File

@ -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
View 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)