32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
![]() |
#!/bin/python
|
||
|
|
||
|
import discord
|
||
|
from discord.ext import commands
|
||
|
from parse_data import update_data, get_covid_data, covid_db
|
||
|
from re import match
|
||
|
from datetime import datetime
|
||
|
from asyncio import sleep
|
||
|
|
||
|
|
||
|
async def background_task(client):
|
||
|
await client.wait_until_ready()
|
||
|
with open('.keys/report_channel_id') as cid:
|
||
|
channel = client.get_channel(int(cid.readline().strip()))
|
||
|
while not client.is_closed():
|
||
|
current_hour_and_minute = [int(t) for t in str(
|
||
|
datetime.now().time()).split(':')[:-1]]
|
||
|
if(current_hour_and_minute[0] == 12 and (current_hour_and_minute[1] == 0)):
|
||
|
update_data()
|
||
|
await channel.send('Daily report from: https://www.worldometers.info/coronavirus/')
|
||
|
await channel.send(get_covid_data('USA'))
|
||
|
await channel.send(get_covid_data('TOTAL'))
|
||
|
await sleep(60)
|
||
|
|
||
|
|
||
|
if(__name__ == '__main__'):
|
||
|
with open('.keys/bot_api.key') as key:
|
||
|
discord_api_key = key.readline().strip()
|
||
|
client = discord.Client()
|
||
|
client.loop.create_task(background_task(client))
|
||
|
client.run(discord_api_key)
|