"""Constructs daily time series of COVID-19 testing data for Guatemala.Official dashboard: https://tablerocovid.mspas.gob.gt/."""importosimporttimeimportpandasaspdfromglobimportglobfromseleniumimportwebdriverfromselenium.webdriver.chrome.optionsimportOptionsfromcowidev.testingimportCountryTestBase
[docs]classGuatemala(CountryTestBase):location="Guatemala"units="people tested"source_label="Ministry of Health and Social Assistance"source_url="https://gtmvigilanciacovid.shinyapps.io/3869aac0fb95d6baf2c80f19f2da5f98"source_url_ref=source_url
[docs]defexport(self):# Options for Chrome WebDriverop=Options()op.add_argument("--disable-notifications")op.add_experimental_option("prefs",{"download.prompt_for_download":False,"download.directory_upgrade":True,"safebrowsing.enabled":True,},)withwebdriver.Chrome(options=op)asdriver:# Setting Chrome to trust downloadsdriver.command_executor._commands["send_command"]=("POST","/session/$sessionId/chromium/send_command",)params={"cmd":"Page.setDownloadBehavior","params":{"behavior":"allow","downloadPath":"tmp"},}command_result=driver.execute("send_command",params)driver.get(self.source_url)time.sleep(3)driver.find_element_by_class_name("fa-file-download").click()time.sleep(1)driver.find_element_by_id("tamizadosFER").click()driver.find_element_by_id("tamizadosFER").click()driver.find_element_by_id("tamizadosFER").click()time.sleep(5)file=glob("tmp/Tamizados*")[0]df=pd.read_csv(file)df=df.filter(regex=r"^20[\d-]{8}$")df=pd.melt(df).groupby("variable",as_index=False).sum()df=df[df["value"]!=0]df=df.rename(columns={"variable":"Date","value":"Daily change in cumulative total"})df=df.pipe(self.pipe_metadata)self.export_datafile(df)os.remove(file)