-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""This code is written by AKmahim""" | ||
|
||
import re | ||
import requests | ||
import sys | ||
|
||
|
||
def find_case(url): | ||
#this take a the url and collect the data about world coronavirus case return 3 data-world_case,death_case,recovered_case | ||
resp = requests.get(url) | ||
if resp.ok is False: | ||
sys.exit("Could not connect with website") | ||
else: | ||
content = resp.text | ||
WC = re.findall(total_pat,content) | ||
DC = re.findall(death_pat,content) | ||
RC = re.findall(recover_pat,content) | ||
|
||
return WC[0],DC[0],RC[0] | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
total_pat = re.compile(r'<div class="maincounter-number">\s+<span style="color:#aaa">(.*?) </span>\s+</div>') | ||
death_pat = re.compile(r'<div class="maincounter-number">\s+<span>(.*?)</span>\s+</div>') | ||
recover_pat =re.compile(r'<div class="maincounter-number" style="color:#8ACA2B ">\s+<span>(.*?)</span>\s+</div>') | ||
world_url = "https://www.worldometers.info/coronavirus/#countries" | ||
bd_url = "https://www.worldometers.info/coronavirus/country/bangladesh/" | ||
tc1,dc1,rc1 = find_case(world_url) | ||
tc2,dc2,rc2 = find_case(bd_url) | ||
|
||
res1 = "World Case---\nCoronavirus Cases: {}\nDeaths: {}\nRecovered: {}\n".format(tc1,dc1,rc1) | ||
res2 = "Bangladesh Case--\nCoronavirus Cases: {}\nDeaths: {}\nRecovered: {}".format(tc2,dc2,rc2) | ||
print(res1) #world case | ||
print(res2) #bangladesh case | ||
|
||
|