from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
from
bs4
import
BeautifulSoup
import
requests
import
sys
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle(
"Python "
)
self
.setGeometry(
100
,
100
,
400
,
500
)
self
.corona()
self
.UiComponents()
self
.show()
def
corona(
self
):
extract_contents
=
lambda
row: [x.text.replace(
'\n'
, '')
for
x
in
row]
SHORT_HEADERS
=
[
'SNo'
,
'State'
,
'Indian-Confirmed'
,
'Foreign-Confirmed'
,
'Cured'
,
'Death'
]
response
=
requests.get(URL).content
soup
=
BeautifulSoup(response,
'html.parser'
)
header
=
extract_contents(soup.tr.find_all(
'th'
))
self
.stats
=
[]
all_rows
=
soup.find_all(
'tr'
)
for
row
in
all_rows:
stat
=
extract_contents(row.find_all(
'td'
))
if
stat:
if
len
(stat)
=
=
5
:
stat
=
['',
*
stat]
self
.stats.append(stat)
elif
len
(stat)
=
=
6
:
self
.stats.append(stat)
self
.stats[
-
1
][
1
]
=
"Total Cases"
self
.stats.remove(
self
.stats[
-
1
])
def
UiComponents(
self
):
self
.combo_box
=
QComboBox(
self
)
self
.combo_box.setGeometry(
100
,
50
,
200
,
40
)
self
.combo_box.setFont(QFont(
'Times'
,
10
))
for
i
in
self
.stats:
self
.combo_box.addItem(i[
2
])
self
.combo_box.activated.connect(
self
.get_cases)
self
.label_total
=
QLabel(
"Total Cases "
,
self
)
self
.label_total.setGeometry(
100
,
300
,
200
,
40
)
self
.label_total.setAlignment(Qt.AlignCenter)
self
.label_total.setStyleSheet(
"border : 2px solid black;"
)
self
.label_reco
=
QLabel(
"Recovered Cases "
,
self
)
self
.label_reco.setGeometry(
100
,
350
,
200
,
40
)
self
.label_reco.setAlignment(Qt.AlignCenter)
self
.label_reco.setStyleSheet(
"border : 2px solid black;"
)
self
.label_death
=
QLabel(
"Total Deaths "
,
self
)
self
.label_death.setGeometry(
100
,
400
,
200
,
40
)
self
.label_death.setAlignment(Qt.AlignCenter)
self
.label_death.setStyleSheet(
"border : 2px solid black;"
)
def
get_cases(
self
):
index
=
self
.combo_box.currentIndex()
total
=
self
.stats[index][
3
]
recovered
=
self
.stats[index][
4
]
deaths
=
self
.stats[index][
5
]
self
.label_total.setText(
"Total Cases : "
+
total)
self
.label_reco.setText(
"Recovered Cases : "
+
recovered)
self
.label_death.setText(
"Total Deaths : "
+
deaths)
App
=
QApplication(sys.argv)
window
=
Window()
window.show()
sys.exit(App.
exec
())