Initial commit.
This commit is contained in:
commit
527723d605
5 changed files with 88 additions and 0 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
**/__pycache__/**
|
||||||
|
**.pyc
|
||||||
|
Pipfile.lock
|
||||||
|
.keys/
|
||||||
|
**/.credentials
|
18
Pipfile
Normal file
18
Pipfile
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
[[source]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
pipfile = "*"
|
||||||
|
autopep8 = "*"
|
||||||
|
pylint = "*"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
pipfile = "*"
|
||||||
|
requests = "*"
|
||||||
|
discord = "*"
|
||||||
|
beautifulsoup4 = "*"
|
||||||
|
|
||||||
|
[required]
|
||||||
|
python = "*" # Replace this with your project's stable Python version
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# COVID-19 Discord Bot
|
||||||
|
|
||||||
|
It's just reporting some numbers and stats from https://www.worldometers.info/coronavirus/
|
29
main.py
Normal file
29
main.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/python
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from parse_data import get_current_data
|
||||||
|
|
||||||
|
|
||||||
|
class MyClient(discord.Client):
|
||||||
|
async def on_ready(self):
|
||||||
|
print('Logged on as', self.user)
|
||||||
|
|
||||||
|
async def on_message(self, message):
|
||||||
|
# don't respond to ourselves
|
||||||
|
if(message.author == self.user):
|
||||||
|
return
|
||||||
|
|
||||||
|
if(message.content == 'ping'):
|
||||||
|
await message.channel.send('pong')
|
||||||
|
|
||||||
|
if(message.content == 'report'):
|
||||||
|
with open('.keys/report_channel_id') as cid:
|
||||||
|
channel = self.get_channel(int(cid.readline().strip()))
|
||||||
|
await channel.send(get_current_data())
|
||||||
|
|
||||||
|
|
||||||
|
if(__name__ == '__main__'):
|
||||||
|
with open('.keys/bot_api.key') as key:
|
||||||
|
client = MyClient()
|
||||||
|
client.run(key.readline().strip())
|
31
parse_data.py
Normal file
31
parse_data.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_data():
|
||||||
|
data_html = requests.get('https://www.worldometers.info/coronavirus/')
|
||||||
|
if(data_html.status_code == '200' or data_html.status_code == 200):
|
||||||
|
parsed_html = BeautifulSoup(data_html.text)
|
||||||
|
table = parsed_html.find('table', id='main_table_countries_today')
|
||||||
|
all_rows = table.findAll('tr')
|
||||||
|
for row in all_rows:
|
||||||
|
if(row and row.findAll('td') and row.find('a')):
|
||||||
|
all_cols = row.findAll('td')
|
||||||
|
if(row.find('a').text == 'USA'):
|
||||||
|
return f'''
|
||||||
|
{row.find('a').text}
|
||||||
|
Total Cases: {all_cols[1].text}
|
||||||
|
New Cases: {all_cols[2].text}
|
||||||
|
Total Deaths: {all_cols[3].text}
|
||||||
|
New Deaths: {all_cols[4].text}
|
||||||
|
Total Recovered: {all_cols[5].text}
|
||||||
|
Active Cases: {all_cols[6].text}
|
||||||
|
Serious/Critical: {all_cols[7].text}
|
||||||
|
Total Cases/1M Population: {all_cols[8].text}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
if(__name__ == '__main__'):
|
||||||
|
print(get_current_data())
|
Reference in a new issue