Created
March 14, 2020 15:45
-
-
Save RajeshKrSahoo/d9ac67546ab5b671f38d8f378adafeb2 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
def scrap_coronaData(): | |
try: | |
file_name='nCOV'+datetime.now().strftime("%d-%m-%Y")+'.csv' | |
# corona_data=pd.read_html('https://www.worldometers.info/coronavirus/#countries')[0]#,header=None)[0] | |
header = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", | |
"X-Requested-With": "XMLHttpRequest" | |
} | |
r = requests.get('https://www.worldometers.info/coronavirus/#countries', headers=header, timeout=10) | |
# soup = bs(r.text, 'html.parser') | |
# return soup | |
'''We also can directly read the data from the get request and parse using Pandas table''' | |
covid_data=pd.read_html(r.text)[0] | |
#print(covid_data) | |
covid_data.fillna(0,inplace=True) | |
covid_data.to_csv(file_name, sep=',', index=False) | |
return covid_data #.sort_values('Country,Other') | |
except Exception as exc: | |
print(f'{exc}') | |
corona_data=scrap_coronaData() | |
def search_country(country=None,df=corona_data): | |
if country == None: | |
print(" Updating for all") | |
df=scrap_coronaData() | |
return df | |
else: | |
country=' '.join([i.capitalize() for i in country.split()]) | |
# if any(str(elem) in ['Iran'] for elem in df['Country,Other'].tolist()): | |
# print('yes present') | |
# else: | |
# print("The Country is not Availble") | |
if country in df['Country,Other'].tolist(): | |
covid_outbreak=df.loc[df['Country,Other']==country] | |
return covid_outbreak | |
else: | |
print("Nope The given Country information is not Avaialable") | |
return f'The given Country information is not Avaialable' | |
# return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment