brightway-lca / bw_hestia_bridge

Consume the HESTIA API in Brightway
https://docs.brightway.dev/projects/hestiabridge/
MIT License
1 stars 0 forks source link

Search the hestia cycles for a cycle that has a specific output #19

Closed cswh closed 1 year ago

cswh commented 1 year ago
# all referring to staging-api
node = bhb.get_hestia_node({"@type": "cycle", "@id": "cx_dtpwud1iu"})
node_output = [i for i in node["products"] if i["term"]["@id"] == "bananaFruit"][0]

# TODO: Search the hestia cycles if a cycle has node_output as an input
# Perhaps in this style?:
bhb.search_hestia({"cycle.inputs.term.@id": node_output["term"]["@id"]})

# And probably in other contexts as well, like looking for cycles with a specific product
node_input = [i for i in node["inputs"] if i["term"]["@id"] == "saplings"][0]
# Perhaps in this style?
bhb.search_hestia({"cycle.products.term.@id": node_input["term"]["@id"]})
cswh commented 1 year ago
os.environ["API_URL"] = 'https://api-staging.hestia.earth' #'https://api.hestia.earth'
os.environ["SEARCH_URL"] = 'https://search-staging.hestia.earth' #'https://search.hestia.earth
from hestia_earth.schema import SchemaType
from hestia_earth.utils.api import find_node, download_hestia, find_node_exact

node = find_node(SchemaType.CYCLE, {"products.term.name": 'Saplings'})
node = download_hestia("exqfz4a8clsx", "cycle")
node["products"]
find_node(SchemaType.CYCLE, {"products.term.@id": 'saplings'})