[docs]classSaintKittsNevis(CountryTestBase):location:str="Saint Kitts and Nevis"units:str="people tested"source_label:str="Ministry of Health"source_url:str="https://covid19.gov.kn/src/stats2/"source_url_ref:str="https://covid19.gov.kn/src/stats2/"regex:dict={"element":r"No. of Persons Tested",}
[docs]defread(self)->pd.DataFrame:"""Read data from source"""soup=get_soup(self.source_url)df=self._parse_data(soup)returndf
[docs]def_parse_data(self,soup:BeautifulSoup)->pd.DataFrame:"""Parse data from soup"""# Get the elementelem=soup.find(text=self.regex["element"]).parentifnotelem:raiseValueError("Element not found, please update the script")# Get the metricscount=self._parse_metrics(elem)# Get the date from soupdate=self._parse_date(soup)df=pd.DataFrame({"Date":[date],"Cumulative total":[count],})returndf
[docs]def_parse_metrics(self,elem:element.Tag)->int:"""Parse metrics from element"""count=elem.find_next_sibling("td").textreturnclean_count(count)
[docs]def_parse_date(self,soup:BeautifulSoup)->str:"""Parse date from soup"""date=soup.find("p").text.lower()returnclean_date(date,"As of %B %d, %Y")
[docs]defpipeline(self,df:pd.DataFrame)->pd.DataFrame:"""Pipeline for data processing"""return(df.pipe(self.pipe_metadata).pipe(self.pipe_merge_current).drop_duplicates(subset=["Cumulative total"],keep="first"))
[docs]defexport(self):"""Export data to csv"""df=self.read().pipe(self.pipeline)self.export_datafile(df)