from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
from
bs4
import
BeautifulSoup as BS
import
requests
import
sys
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle(
"Python "
)
self
.setGeometry(
100
,
100
,
400
,
500
)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
self
.country
=
[
"india"
,
"us"
,
"spain"
,
"china"
,
"russia"
,
"pakistan"
,
"nepal"
,
"italy"
,
"spain"
,
"uk"
,
"brazil"
]
self
.combo_box
=
QComboBox(
self
)
self
.combo_box.setGeometry(
100
,
50
,
200
,
40
)
self
.combo_box.setFont(QFont(
'Times'
,
10
))
for
i
in
self
.country:
i
=
i.upper()
self
.combo_box.addItem(i)
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()
country_name
=
self
.country[index]
data
=
requests.get(url)
soup
=
BS(data.text,
'html.parser'
)
cases
=
soup.find_all(
"div"
,
class_
=
"maincounter-number"
)
total
=
cases[
0
].text
total
=
total[
1
:
len
(total)
-
2
]
recovered
=
cases[
2
].text
recovered
=
recovered[
1
:
len
(recovered)
-
1
]
deaths
=
cases[
1
].text
deaths
=
deaths[
1
:
len
(deaths)
-
1
]
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
())