|
| 1 | +"""This code is written by AKmahim""" |
| 2 | + |
| 3 | +import re |
| 4 | +import requests |
| 5 | +import sys |
| 6 | + |
| 7 | + |
| 8 | +def find_case(url): |
| 9 | + #this take a the url and collect the data about world coronavirus case return 3 data-world_case,death_case,recovered_case |
| 10 | + resp = requests.get(url) |
| 11 | + if resp.ok is False: |
| 12 | + sys.exit("Could not connect with website") |
| 13 | + else: |
| 14 | + content = resp.text |
| 15 | + WC = re.findall(total_pat,content) |
| 16 | + DC = re.findall(death_pat,content) |
| 17 | + RC = re.findall(recover_pat,content) |
| 18 | + |
| 19 | + return WC[0],DC[0],RC[0] |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +if __name__ == "__main__": |
| 28 | + total_pat = re.compile(r'<div class="maincounter-number">\s+<span style="color:#aaa">(.*?) </span>\s+</div>') |
| 29 | + death_pat = re.compile(r'<div class="maincounter-number">\s+<span>(.*?)</span>\s+</div>') |
| 30 | + recover_pat =re.compile(r'<div class="maincounter-number" style="color:#8ACA2B ">\s+<span>(.*?)</span>\s+</div>') |
| 31 | + world_url = "https://www.worldometers.info/coronavirus/#countries" |
| 32 | + bd_url = "https://www.worldometers.info/coronavirus/country/bangladesh/" |
| 33 | + tc1,dc1,rc1 = find_case(world_url) |
| 34 | + tc2,dc2,rc2 = find_case(bd_url) |
| 35 | + |
| 36 | + res1 = "World Case---\nCoronavirus Cases: {}\nDeaths: {}\nRecovered: {}\n".format(tc1,dc1,rc1) |
| 37 | + res2 = "Bangladesh Case--\nCoronavirus Cases: {}\nDeaths: {}\nRecovered: {}".format(tc2,dc2,rc2) |
| 38 | + print(res1) #world case |
| 39 | + print(res2) #bangladesh case |
| 40 | + |
| 41 | + |
0 commit comments