-
Notifications
You must be signed in to change notification settings - Fork 16
/
coronavirus.py
83 lines (68 loc) · 2.82 KB
/
coronavirus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from selenium import webdriver
from time import sleep
import re
from datetime import datetime
import smtplib
class Coronavirus():
def __init__(self):
self.driver = webdriver.Chrome()
def get_data(self):
#try:
self.driver.get('https://www.worldometers.info/coronavirus/')
table = self.driver.find_element_by_xpath('//*[@id="main_table_countries_today"]/tbody[1]')
country_element = table.find_element_by_xpath("//td[contains(., 'USA')]")
row = country_element.find_element_by_xpath("./..")
data = row.text.split(" ")
total_cases = data[1]
new_cases = data[2]
total_deaths = data[3]
new_deaths = data[4]
active_cases = data[5]
total_recovered = data[6]
serious_critical = data[7]
#total_cases = row.find_element_by_class_name('sorting_1')
#new_cases = row.find_element_by_xpath("//td[3]")
#total_deaths = row.find_element_by_xpath("//td[4]")
#new_deaths = row.find_element_by_xpath("//td[5]")
#active_cases = row.find_element_by_xpath("//td[6]")
#total_recovered = row.find_element_by_xpath("//td[7]")
#serious_critical = row.find_element_by_xpath("//td[8]")
print("Country: " + country_element.text)
print("Total cases: " + total_cases)
print("New cases: " + new_cases)
print("Total deaths: " + total_deaths)
print("New deaths: " + new_deaths)
print("Active cases: " + active_cases)
print("Total recovered: " + total_recovered)
print("Serious, critical cases: " + serious_critical)
send_mail(country_element.text, total_cases, new_cases, total_deaths, new_deaths, active_cases, total_recovered, serious_critical)
self.driver.close()
#except:
self.driver.quit()
def send_mail(country_element, total_cases, new_cases, total_deaths, new_deaths, active_cases, total_recovered, serious_critical):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('email', 'password')
subject = 'Coronavirus stats in your country today!'
body = 'Today in ' + country_element + '\
\nThere is new data on coronavirus:\
\nTotal cases: ' + total_cases +'\
\nNew cases: ' + new_cases + '\
\nTotal deaths: ' + total_deaths + '\
\nNew deaths: ' + new_deaths + '\
\nActive cases: ' + active_cases + '\
\nTotal recovered: ' + total_recovered + '\
\nSerious, critical cases: ' + serious_critical + '\
\nCheck the link: https://www.worldometers.info/coronavirus/'
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
'Coronavirus',
'email',
msg
)
print('Hey Email has been sent!')
server.quit()
bot = Coronavirus()
bot.get_data()