From 7c3df6db9a78efabcd6f0d863c3ca3463b089283 Mon Sep 17 00:00:00 2001 From: Daniel Heinesen Date: Thu, 5 Sep 2024 09:07:31 +0200 Subject: [PATCH] Fixes some bugs with toml --- src/pyaro_readers/eeareader/eeadownloader.py | 55 +++++++++----------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/pyaro_readers/eeareader/eeadownloader.py b/src/pyaro_readers/eeareader/eeadownloader.py index 2004aab..62da686 100644 --- a/src/pyaro_readers/eeareader/eeadownloader.py +++ b/src/pyaro_readers/eeareader/eeadownloader.py @@ -7,7 +7,7 @@ from pathlib import Path -from tomli import tomllib +import tomli as tomllib from tqdm import tqdm @@ -32,7 +32,6 @@ class EEADownloader: METADATFILE = Path(__file__).parent / "metadata.csv" DATAFILE = Path(__file__).parent / "data.toml" - request_body = dict(contries=[], cities=[], properties=[], datasets=[], source="") def __init__( @@ -108,21 +107,19 @@ def get_station_metadata(self) -> dict: return metadata def get_pollutants(self) -> dict: - with open(self.DATAFILE, "r") as f: - poll = tomlib.load(f)["pollutant"] + with open(self.DATAFILE, "rb") as f: + poll = tomllib.load(f)["pollutant"] return poll - + def get_default_pollutants(self) -> list[str]: - with open(self.DATAFILE, "r") as f: - poll = tomlib.load(f)["defaults"]["pollutants"] + with open(self.DATAFILE, "rb") as f: + poll = tomllib.load(f)["defaults"]["pollutants"] return poll def make_pollutant_url_list(self, pollutants: list[str]) -> list[str]: urls = [] - with open( - self.DATAFILE - ) as f: - poll = tomlib.load(f)["pollutant"] + with open(self.DATAFILE, "rb") as f: + poll = tomllib.load(f)["pollutant"] for key in poll: if poll[key] in pollutants: urls.append(self.URL_POLLUTANT + key) @@ -258,21 +255,21 @@ def postprocess( if __name__ == "__main__": - - - - # eead = EEADownloader() - # # eead.download_default( - # # Path( - # # "/home/danielh/Documents/pyaerocom/pyaro-readers/src/pyaro_readers/eeareader/data" - # # ) - # # ) - - # eead.postprocess_all_files( - # Path( - # "/home/danielh/Documents/pyaerocom/pyaro-readers/src/pyaro_readers/eeareader/data" - # ), - # Path( - # "/home/danielh/Documents/pyaerocom/pyaro-readers/src/pyaro_readers/eeareader/renamed" - # ), - # ) + app() + + +# eead = EEADownloader() +# # eead.download_default( +# # Path( +# # "/home/danielh/Documents/pyaerocom/pyaro-readers/src/pyaro_readers/eeareader/data" +# # ) +# # ) + +# eead.postprocess_all_files( +# Path( +# "/home/danielh/Documents/pyaerocom/pyaro-readers/src/pyaro_readers/eeareader/data" +# ), +# Path( +# "/home/danielh/Documents/pyaerocom/pyaro-readers/src/pyaro_readers/eeareader/renamed" +# ), +# )