[docs]classKosovo(CountryTestBase):location:str="Kosovo"units:str="tests performed"source_label:str="National Institute of Public Health of Kosovo"source_url:str=("https://datastudio.google.com/embed/u/0/reporting/2e546d77-8f7b-4c35-8502-38533aa0e9e8/page/tI3oB")source_url_ref:str="https://datastudio.google.com/embed/u/0/reporting/2e546d77-8f7b-4c35-8502-38533aa0e9e8"regex:dict={"date":"Përditësimi i fundit:","count":"Gjithsej të testuar",}
[docs]defread(self)->pd.DataFrame:"""Read data from source"""withget_driver()asdriver:driver.get(self.source_url)time.sleep(10)df=self._parse_data(driver)returndf
[docs]def_parse_data(self,driver:WebDriver)->pd.DataFrame:"""Parse data from source"""# Extract dataforblockindriver.find_elements_by_class_name("kpimetric"):ifself.regex["count"]inblock.find_element_by_class_name("kpi-label").text:count=clean_count(block.find_element_by_class_name("valueLabel").text)forblockindriver.find_elements_by_class_name("cell"):ifself.regex["date"]inblock.text:date_str=block.textifnotcountornotdate_str:raiseValueError("Count or date not found, please update the script")# Parse datadate=self._parse_date(date_str)# Create dataframedf=pd.DataFrame({"Date":[date],"Cumulative total":[count],})returndf
[docs]def_parse_date(self,date:str)->str:"""Parse date from soup"""day_month=date.split("Përditësimi i fundit:")[1].strip().lower()year=datetime.now().yeardate=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)