[docs]classAntiguaBarbuda(CountryTestBase):location:str="Antigua and Barbuda"units:str="tests performed"source_label:str="Ministry of Health"source_url:str="https://covid19.gov.ag"source_url_ref:str="https://covid19.gov.ag"
[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="Tests Done").parentifnotelem:raiseValueError("Element not found, please update the script")# Get the metricscount=self._parse_metrics(elem)# Get the datedate=self._parse_date(elem)df=pd.DataFrame({"Date":[date],"Cumulative total":[count],})returndf
[docs]def_parse_metrics(self,elem:element.Tag)->int:"""Parse metrics from element"""count=clean_count(elem.find_next_sibling("p",class_="case-Number").text)returncount
[docs]def_parse_date(self,elem:element.Tag)->str:"""Parse date from element"""parent_elem=elem.find_parent()date_str=parent_elem.find_previous_sibling("h2").textreturnclean_date(date_str,"[Updated on %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)