kind of big update. adding corona virus stats for CA and also modifying the docker file to just use python instead of alpine

This commit is contained in:
luke 2020-03-26 09:12:34 -07:00
parent ff462e9d35
commit 2e02cb90d1
5 changed files with 59 additions and 35 deletions

View File

@ -2,14 +2,5 @@ FROM python:3.6-buster AS builder
RUN apt-get update && apt-get install -y gcc python-pip RUN apt-get update && apt-get install -y gcc python-pip
ADD app/requirements.txt /requirements.txt ADD app/requirements.txt /requirements.txt
RUN pip install -U pip && pip install -r requirements.txt RUN pip install -U pip && pip install -r requirements.txt
#stage 2
FROM python:3.6-alpine3.9
RUN apk update && \
apk add --no-cache docker
COPY --from=builder /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages
ADD app /app ADD app /app
CMD python /app/dragon-bot.py CMD python /app/dragon-bot.py

View File

@ -3,15 +3,6 @@ RUN apt-get update && apt-get install -y gcc python-pip
ADD app/requirements.txt /requirements.txt ADD app/requirements.txt /requirements.txt
RUN pip install -U pip pylint && pip install -r requirements.txt RUN pip install -U pip pylint && pip install -r requirements.txt
#stage 2
FROM python:3.6-alpine3.9
RUN apk update && \
apk add --no-cache docker
COPY --from=builder /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages
COPY --from=builder /usr/local/bin/pylint /usr/local/bin/pylint
ADD app /app ADD app /app
RUN printf "\n\nTesting your python code for errors\n\n" && \ RUN printf "\n\nTesting your python code for errors\n\n" && \
pylint -E /app/*.py pylint -E /app/*.py

36
app/corona.py Normal file
View File

@ -0,0 +1,36 @@
from pandas import read_csv
import pandas as pd
import requests
import os
import discord
def get_csv():
git_url = 'https://api.github.com/repos/CSSEGISandData/COVID-19/contents/csse_covid_19_data/csse_covid_19_daily_reports'
git_blob = requests.get(git_url).json()[-2]
file_name = git_blob['name']
download_url = git_blob['download_url']
local_csv = "/app/%s" % file_name
if not os.path.exists(local_csv):
print("no local csv found, downloading latest")
# url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/%s.csv" % date
r = requests.get(download_url, allow_redirects=True)
open(local_csv, 'wb').write(r.content)
return local_csv
def sum_numbers():
series = read_csv(get_csv(), header=0, parse_dates=[0], index_col=0, squeeze=True)
california = series.loc[series['Province_State'] == 'California'].sum()
confirmed = california['Confirmed']
deaths = california['Deaths']
recovered = california['Recovered']
embed = discord.Embed(description='Most recent Corona stats for California', color=0x428bca, type="rich")
embed.set_author(name="CSSE at Johns Hopkins University", icon_url='https://avatars2.githubusercontent.com/u/60674295')
embed.add_field(name='Confirmed Cases', value=confirmed)
embed.add_field(name='Recovered Cases', value=recovered)
embed.add_field(name='Deaths', value=deaths)
embed.add_field(name='Source', value='https://github.com/CSSEGISandData/COVID-19')
return embed

View File

@ -13,12 +13,12 @@ import re
import animals import animals
import core_utils import core_utils
import corona
import datetime import datetime
import decide import decide
import define_word import define_word
import dice import dice
import discord import discord
import docker
import eight_ball import eight_ball
import emoji import emoji
import excuse import excuse
@ -135,6 +135,11 @@ async def on_message(message):
embed_description="[Direct Link]({})".format(user.avatar_url.replace('.webp', '.png')) embed_description="[Direct Link]({})".format(user.avatar_url.replace('.webp', '.png'))
) )
) )
if message.content.startswith('!birb'):
await client.send_message(
message.channel,
embed=generate_embed(embed_url=animals.get_birb())
)
if message.content.startswith('!clap'): if message.content.startswith('!clap'):
await client.delete_message(message) await client.delete_message(message)
@ -153,6 +158,13 @@ async def on_message(message):
await client.delete_message(message) await client.delete_message(message)
await client.purge_from(message.channel, limit=10, check=is_bot) await client.purge_from(message.channel, limit=10, check=is_bot)
if message.content.startswith('!corona'):
await client.send_message(
message.channel,
embed=corona.sum_numbers()
)
if message.content.startswith('!decide'): if message.content.startswith('!decide'):
await client.send_message( await client.send_message(
message.channel, message.channel,
@ -174,18 +186,6 @@ async def on_message(message):
embed=generate_embed(embed_url=animals.get_dog()) embed=generate_embed(embed_url=animals.get_dog())
) )
if message.content.startswith('!birb'):
await client.send_message(
message.channel,
embed=generate_embed(embed_url=animals.get_birb())
)
if message.content.startswith('!redpanda'):
await client.send_message(
message.channel,
embed=generate_embed(embed_url=animals.random_red_panda())
)
if message.content.startswith('!excuse'): if message.content.startswith('!excuse'):
await client.send_message(message.channel, excuse.get_excuse()) await client.send_message(message.channel, excuse.get_excuse())
@ -361,6 +361,12 @@ async def on_message(message):
return return
await client.purge_from(message.channel, limit=num, check=is_me) await client.purge_from(message.channel, limit=num, check=is_me)
if message.content.startswith('!redpanda'):
await client.send_message(
message.channel,
embed=generate_embed(embed_url=animals.random_red_panda())
)
if message.content.startswith('!roles'): if message.content.startswith('!roles'):
await client.send_message( await client.send_message(
message.channel, message.channel,

View File

@ -1,10 +1,10 @@
beautifulsoup4 beautifulsoup4
discord.py==0.16.12 discord.py==0.16.12
docker
gTTS gTTS
gTTS-token gTTS-token
lxml
pandas
pyowm pyowm
requests requests
wikipedia wikipedia
wolframalpha wolframalpha
lxml