[docs]classMorocco(CountryTestBase):location:str="Morocco"units:str="people tested"source_label:str="Ministry of Health"source_url:str="http://www.covidmaroc.ma/Pages/AccueilAR.aspx"source_url_ref:str="http://www.covidmaroc.ma/Pages/AccueilAR.aspx"regex:dict={"date":r"00 (\d{1,2}\-\d{2}\-20\d{2})","count":r"\s+",}
[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 metricscount=self._parse_metrics(soup)# Get the datedate=self._parse_date(soup)df=pd.DataFrame({"Date":[date],"Cumulative total":[count],})returndf
[docs]def_parse_metrics(self,soup:BeautifulSoup)->int:"""Parse metrics from soup"""text=soup.find("table").find_all("span")[1].textcount=re.sub(self.regex["count"],"",text)returnclean_count(count)
[docs]def_parse_date(self,soup:BeautifulSoup)->str:"""Parse date from soup"""date_str=soup.find("table").find("span").text.replace("\u200b","")returnextract_clean_date(date_str,self.regex["date"],"%d-%m-%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)