diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5fb5a07..308a8cb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,6 @@ repos: rev: v4.4.0 hooks: - id: trailing-whitespace - - id: check-added-large-files - id: check-ast - id: check-json - id: check-merge-conflict diff --git a/ecoinvent_interface/data/mappings.zip b/ecoinvent_interface/data/mappings.zip new file mode 100644 index 0000000..f3910a2 Binary files /dev/null and b/ecoinvent_interface/data/mappings.zip differ diff --git a/ecoinvent_interface/mapping.py b/ecoinvent_interface/mapping.py index 302e58b..122bace 100644 --- a/ecoinvent_interface/mapping.py +++ b/ecoinvent_interface/mapping.py @@ -1,3 +1,5 @@ +import json +import zipfile from pathlib import Path from time import sleep from typing import Optional @@ -7,6 +9,8 @@ from . import CachedStorage, EcoinventProcess, Settings +DATA_DIR = Path(__file__).parent.resolve() / "data" + def get_rp_text(exchanges: list) -> str: rp_exchanges = [ @@ -75,3 +79,15 @@ def create_local_mapping(self, key: str, verbose: bool) -> None: ) return local_data + + +def get_cached_mapping(version: str, system_model: str) -> dict: + zf = zipfile.ZipFile(DATA_DIR / "mappings.zip") + try: + catalogue = { + (o["version"], o["system_model"]): o + for o in json.load(zf.open("catalogue.json")) + } + return json.load(zf.open(catalogue[(version, system_model)]["filename"])) + except KeyError: + raise KeyError(f"Combination {version} + {system_model} not yet cached")