Skip to content

Instantly share code, notes, and snippets.

@henhuy
Last active December 7, 2022 11:15
Show Gist options
  • Save henhuy/679e695a1fdead014c1662e5f4b1e77d to your computer and use it in GitHub Desktop.
Save henhuy/679e695a1fdead014c1662e5f4b1e77d to your computer and use it in GitHub Desktop.
MOSS registration of artifact
import requests
from urllib.parse import quote
MOSS_URL = "http://moss.tools.dbpedia.org/annotation-api-demo/submit"
METADATA_URL = "https://openenergy-platform.org/api/v0/schema/model_draft/tables/umas_ninja_pv_country_de_merra_2_nuts_2_corrected/meta/"
DATABUS_ARTIFACT = "https://energy.databus.dbpedia.org/henhuy/AP4/modex_capacity_factor"
DATABUS_VERSION = "https://energy.databus.dbpedia.org/henhuy/AP4/modex_capacity_factor/v1"
DATABUS_DATA = "https://energy.databus.dbpedia.org/henhuy/AP4/modex_capacity_factor/v1/modex_capacity_factor_type=metadata.json"
def submit_metadata_to_moss(databus_identifier, metadata):
api_uri = f"{MOSS_URL}?id={quote(databus_identifier)}"
response = requests.put(
api_uri, headers={"Content-Type": "application/ld+json"}, json=metadata
)
if response.status_code != 200:
raise Exception(
f"Could not submit metadata for DI '{databus_identifier}' to MOSS. "
f"Reason: {response.text}"
)
# I get response 400: 'Failed: https://energy.databus.dbpedia.org/henhuy/AP4/modex_capacity_factor is no valid Databus ID'
# when calling function (metadata belongs to different table, but is valid JSON-LD):
resp = requests.get(METADATA_URL)
md = resp.json()
submit_metadata_to_moss(DATABUS_ARTIFACT, md)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment