[docs]classGibraltar(CountryTestBase):location:str="Gibraltar"units:str="tests performed"source_label:str="The Department of Public Health"source_url:str="https://healthygibraltar.org/news/update-on-wuhan-coronavirus/"source_url_ref:str="https://healthygibraltar.org/news/update-on-wuhan-coronavirus/"regex:dict={"date":r"valid as of (\d{1,2})\w+ (\w+ 20\d{2})","count":r"Results received: ([\d,]+)",}
[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"""# Extract text from souptext=soup.get_text().replace("\xa0","")# Get the metricscount=self._parse_metrics(text)# Get the datedate=self._parse_date(text)df=pd.DataFrame({"Date":[date],"Cumulative total":[count],})returndf
[docs]def_parse_metrics(self,text:str)->int:"""Parse metrics from text"""count=re.search(self.regex["count"],text).group(1)returnclean_count(count)
[docs]def_parse_date(self,text:str)->str:"""Parse date from text"""day,month_year=re.search(self.regex["date"],text.lower()).group(1,2)date=f"{day}{month_year}"returnclean_date(date,"%d %B %Y")
[docs]defpipeline(self,df:pd.DataFrame)->pd.DataFrame:"""Pipeline for data processing"""returndf.pipe(self.pipe_metadata)
[docs]defexport(self):"""Export data to csv"""df=self.read().pipe(self.pipeline)self.export_datafile(df,attach=True)