Created
September 21, 2020 02:16
-
-
Save Atreyagaurav/67ef5ea205b0a6e9d8e94ef8131e170b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# use the following lines in your conky .conf | |
# important to use execpi to get the colors from the scripts right | |
# ${color e43526}COVID-19 UPDATE:${color} | |
# ${execpi 60 python ~/scripts/corona.py} | |
import requests | |
import re | |
from bs4 import BeautifulSoup | |
COLORS = { | |
'reset':'$color', | |
'redish':'${color ff104b}', | |
'blue':'${color 0000ff}', | |
'green':'${color 00ff00}', | |
'yellow':'${color ffff00}' | |
} | |
def output(report): | |
print(" * "+COLORS['yellow'] +'Total Confirmed: '+f'{report[1]}' + COLORS['reset']) | |
print(" * "+COLORS['redish'] + 'Deaths: ' + f'{report[3]}' + COLORS['reset']) | |
print(" * "+COLORS['green'] + 'Recovered: '+ f'{report[5]}' + COLORS['reset']) | |
r = requests.get('https://www.worldometers.info/coronavirus/') | |
soup =BeautifulSoup(r.text,'html.parser') | |
main_count = soup.find_all('div',{'class':'maincounter-number'}) | |
return_string = [] | |
for m in main_count: | |
return_string += m.parent.text.split('\n') | |
report = list(filter(lambda x:x,return_string)) | |
print('World :-') | |
output(report) | |
countries = ['Nepal','India','USA'] | |
for country in countries: | |
country_obj = soup.find('td',text=country) | |
country_list = [st.text for st in country_obj.parent.children if st!='\n'] | |
if not country_list[4].strip(): | |
country_list[4]=0 | |
for i in (1,3,5): | |
report[i]=country_list[i+1] | |
print(country,':-') | |
output(report) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment