handle monthly fuel price download through script

This commit is contained in:
Fabian Neumann 2023-08-06 09:01:56 +02:00
parent 18297a6f13
commit 8d19043205
2 changed files with 39 additions and 8 deletions

View File

@ -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"

View File

@ -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}")