diff --git a/rules/retrieve.smk b/rules/retrieve.smk index 0f590bf9..0b60ee2e 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -220,12 +220,6 @@ if config["enable"]["retrieve"]: if config["enable"]["retrieve"]: rule retrieve_monthly_fuel_prices: - input: - HTTP.remote( - "https://www.destatis.de/EN/Themes/Economy/Prices/Publications/Downloads-Energy-Price-Trends/energy-price-trends-xlsx-5619002.xlsx?__blob=publicationFile", - keep_local=True, - static=True, - ), output: "data/validation/energy-price-trends-xlsx-5619002.xlsx", log: @@ -233,5 +227,7 @@ if config["enable"]["retrieve"]: resources: mem_mb=5000, retries: 2 - run: - move(input[0], output[0]) + conda: + "../envs/environment.yaml" + script: + "../scripts/retrieve_monthly_fuel_prices.py" diff --git a/scripts/retrieve_monthly_fuel_prices.py b/scripts/retrieve_monthly_fuel_prices.py new file mode 100644 index 00000000..11e351ce --- /dev/null +++ b/scripts/retrieve_monthly_fuel_prices.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: : 2023 The PyPSA-Eur Authors +# +# SPDX-License-Identifier: MIT +""" +Retrieve monthly fuel prices from Destatis. +""" + +import logging + +logger = logging.getLogger(__name__) + +from pathlib import Path + +from _helpers import configure_logging, progress_retrieve + +if __name__ == "__main__": + if "snakemake" not in globals(): + from _helpers import mock_snakemake + + snakemake = mock_snakemake("retrieve_monthly_fuel_prices") + rootpath = ".." + else: + rootpath = "." + configure_logging(snakemake) + + url = "https://www.destatis.de/EN/Themes/Economy/Prices/Publications/Downloads-Energy-Price-Trends/energy-price-trends-xlsx-5619002.xlsx?__blob=publicationFile" + + to_fn = Path(rootpath) / Path(snakemake.output[0]) + + logger.info(f"Downloading monthly fuel prices from '{url}'.") + disable_progress = snakemake.config["run"].get("disable_progressbar", False) + progress_retrieve(url, to_fn, disable=disable_progress) + + logger.info(f"Monthly fuel prices available at {to_fn}")