Yangi formatda davom etish uchun: https://uzfor.net/view.php?act=post&id=83934
Postga havola
STRaKER [83] [off]
Salom, forumdoshlar!
Har kuni yangilik saytlarga kirib vaqt, mb sarflamasdan koronavirus kasalanganlari va sog'ayganlarini ko'rish uchun python script yasagandim, buni sizlar bilan ham baham ko'rgim keldi:
buni ishlatish uchun kompyuteringizda python3 o'rnatilgan bo'lishi kerak.
va qo'shimcha ushbu modullar:
pip3 install beautifulsoup4
pip3 install termcolor
python code:
from bs4 import BeautifulSoup
from urllib.request import urlopen
from termcolor import colored
def percentage_of(total, number):
total = int(total)
per = int(number)
result = per / (total / 100)
return round(result, 2)
class Covid(object):
def __init__(self):
self.url = "https://kun.uz/uz/page/about"
self.content = urlopen(self.url).read()
self.soup = BeautifulSoup(self.content, features="html.parser")
self.cases, self.recovered, self.death = self.soup.find_all('b')
self.cases = self.cases.string
self.recovered = self.recovered.string
self.death = self.death.string
self.exist = int(self.cases) - int(self.recovered) - int(self.death)
self.recovery_per = str(percentage_of(self.cases, self.recovered))
self.death_per = str(percentage_of(self.cases, self.death))
self.exist_per = str(percentage_of(self.cases, self.exist))
def current(self):
print("Kasalanganlar: " + colored(self.cases, 'cyan'))
print("Tuzalganlar: " + colored(self.recovered, 'green') + " (" + self.recovery_per + "%)")
print("Vafot etganlar: " + colored(self.death, 'red') + " (" + self.death_per + "%)")
print("Hozirda mavjud: " + colored(self.exist, 'blue') + " (" + self.exist_per + "%)")
Cov = Covid()
Cov.current()
Har kuni yangilik saytlarga kirib vaqt, mb sarflamasdan koronavirus kasalanganlari va sog'ayganlarini ko'rish uchun python script yasagandim, buni sizlar bilan ham baham ko'rgim keldi:
buni ishlatish uchun kompyuteringizda python3 o'rnatilgan bo'lishi kerak.
va qo'shimcha ushbu modullar:
pip3 install beautifulsoup4
pip3 install termcolor
python code:
from bs4 import BeautifulSoup
from urllib.request import urlopen
from termcolor import colored
def percentage_of(total, number):
total = int(total)
per = int(number)
result = per / (total / 100)
return round(result, 2)
class Covid(object):
def __init__(self):
self.url = "https://kun.uz/uz/page/about"
self.content = urlopen(self.url).read()
self.soup = BeautifulSoup(self.content, features="html.parser")
self.cases, self.recovered, self.death = self.soup.find_all('b')
self.cases = self.cases.string
self.recovered = self.recovered.string
self.death = self.death.string
self.exist = int(self.cases) - int(self.recovered) - int(self.death)
self.recovery_per = str(percentage_of(self.cases, self.recovered))
self.death_per = str(percentage_of(self.cases, self.death))
self.exist_per = str(percentage_of(self.cases, self.exist))
def current(self):
print("Kasalanganlar: " + colored(self.cases, 'cyan'))
print("Tuzalganlar: " + colored(self.recovered, 'green') + " (" + self.recovery_per + "%)")
print("Vafot etganlar: " + colored(self.death, 'red') + " (" + self.death_per + "%)")
print("Hozirda mavjud: " + colored(self.exist, 'blue') + " (" + self.exist_per + "%)")
Cov = Covid()
Cov.current()