11"""
2- This script demonstrates fetching simple COVID-19 statistics from the Worldometers archive site
3- using lxml. lxml is chosen over BeautifulSoup for its speed and convenience in Python web projects
4- (such as Django or Flask).
2+ This script demonstrates fetching simple COVID-19 statistics from the
3+ Worldometers archive site using lxml. lxml is chosen over BeautifulSoup
4+ for its speed and convenience in Python web projects (such as Django or
5+ Flask).
56"""
67
78# /// script
@@ -36,15 +37,19 @@ def covid_stats(
3637 response .raise_for_status ()
3738 except httpx .TimeoutException :
3839 print (
39- "Request timed out. Please check your network connection or try again later."
40+ "Request timed out. Please check your network connection "
41+ "or try again later."
4042 )
4143 return CovidData ("N/A" , "N/A" , "N/A" )
4244 except httpx .HTTPStatusError as e :
4345 print (f"HTTP error occurred: { e } " )
4446 return CovidData ("N/A" , "N/A" , "N/A" )
4547 data = html .fromstring (response .content ).xpath (xpath_str )
4648 if len (data ) != 3 :
47- print ("Unexpected data format. The page structure may have changed." )
49+ print (
50+ "Unexpected data format. The page structure may have "
51+ "changed."
52+ )
4853 return CovidData ("N/A" , "N/A" , "N/A" )
4954 return CovidData (* data )
5055
@@ -55,4 +60,4 @@ def covid_stats(
5560 "Total deaths due to COVID-19 in the world: {}\n "
5661 "Total COVID-19 patients recovered in the world: {}"
5762 )
58- print (fmt .format (* covid_stats ()))
63+ print (fmt .format (* covid_stats ()))
0 commit comments