Code Duplication    Length = 20-26 lines in 2 locations

src/egon/data/datasets/data_bundle/__init__.py 1 location

@@ 14-39 (lines=26) @@
11
from egon.data.datasets import Dataset
12
13
14
def download():
15
    """
16
    Download small scale input data from Zenodo
17
    Parameters
18
    ----------
19
20
    """
21
    data_bundle_path = Path(".") / "data_bundle_egon_data"
22
    # Delete folder if it already exists
23
    if data_bundle_path.exists() and data_bundle_path.is_dir():
24
        shutil.rmtree(data_bundle_path)
25
    # Get parameters from config and set download URL
26
    sources = config.datasets()["data-bundle"]["sources"]["zenodo"]
27
    url = (
28
        f"https://zenodo.org/record/{sources['deposit_id']}/files/"
29
        "data_bundle_egon_data.zip"
30
    )
31
    target_file = config.datasets()["data-bundle"]["targets"]["file"]
32
33
    # check if file exists
34
    if not Path(target_file).exists():
35
        # Retrieve files
36
        urlretrieve(url, target_file)
37
38
    with zipfile.ZipFile(target_file, "r") as zip_ref:
39
        zip_ref.extractall(".")
40
41
42
class DataBundle(Dataset):

src/egon/data/datasets/scenario_parameters/__init__.py 1 location

@@ 258-277 (lines=20) @@
255
    return values
256
257
258
def download_pypsa_technology_data():
259
    """Downlad PyPSA technology data results."""
260
    data_path = Path(".") / "pypsa_technology_data"
261
    # Delete folder if it already exists
262
    if data_path.exists() and data_path.is_dir():
263
        shutil.rmtree(data_path)
264
    # Get parameters from config and set download URL
265
    sources = egon.data.config.datasets()["pypsa-technology-data"]["sources"][
266
        "zenodo"
267
    ]
268
    url = f"""https://zenodo.org/record/{sources['deposit_id']}/files/{sources['file']}"""
269
    target_file = egon.data.config.datasets()["pypsa-technology-data"][
270
        "targets"
271
    ]["file"]
272
273
    # Retrieve files
274
    urlretrieve(url, target_file)
275
276
    with zipfile.ZipFile(target_file, "r") as zip_ref:
277
        zip_ref.extractall(".")
278
279
280
class ScenarioParameters(Dataset):