Skip to content

Instantly share code, notes, and snippets.

@ahmedazizkhelifi
Created March 14, 2020 14:50
Show Gist options
  • Save ahmedazizkhelifi/dda4f62a8cc6e85d19de24d6de2ce232 to your computer and use it in GitHub Desktop.
Save ahmedazizkhelifi/dda4f62a8cc6e85d19de24d6de2ce232 to your computer and use it in GitHub Desktop.
from win10toast import ToastNotifier
from bs4 import BeautifulSoup
import time
import requests
country = "Tunisia"
notification_duration = 10
refresh_time = 60 #seconds
while True:
html_page = requests.get("https://www.worldometers.info/coronavirus/")
bs = BeautifulSoup(html_page.content, 'html.parser')
search = bs.select("div tbody tr td")
start = -1
end = -1
for i in range(len(search)):
if search[i].get_text().find(country) !=-1:
start = i
break
array = []
for i in range(1,8):
try:
array = array + [int(search[start+i].get_text())]
except:
array = array + [0]
message = "Total infected = {}, New Case = {}, Total Deaths = {}, New Deaths {}, Recovred = {}, Active Case = {}, Serious Critical = {}".format(*array)
toaster = ToastNotifier()
toaster.show_toast("Coronavirus {}".format(country) , message, duration = notification_duration , icon_path ="icon.ico")
time.sleep(refresh_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment