This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
covid-19-discord-bot/lib/covid_report_lib.py

25 lines
1.2 KiB
Python

#!/bin/python
from lib.parse_data import update_data, get_covid_data, get_top_data
from datetime import datetime
from pytz import timezone
from asyncio import sleep
from math import floor
async def background_task(client, config_dict):
await client.wait_until_ready()
update_data()
channel = client.get_channel(config_dict['report_channel_id'])
while not client.is_closed():
current_hour_and_minute = [int(t) for t in str(
datetime.now(timezone(config_dict['report_timezones'])).time()).split(':')[:-1]]
for rt in config_dict['report_times']:
if(current_hour_and_minute[0] == floor(rt/100) and (current_hour_and_minute[1] == rt % 100)):
update_data()
await channel.send('Daily report from: https://www.worldometers.info/coronavirus/')
for selection in config_dict['report_selections']:
await channel.send(get_covid_data(selection))
await channel.send(get_top_data(config_dict['report_top_number']))
elif(current_hour_and_minute[1] == 0 or current_hour_and_minute[1] == 30):
update_data()
await sleep(60)