Skip to content
Snippets Groups Projects
Commit c3d5fd12 authored by Nicolas Fabas's avatar Nicolas Fabas :croissant:
Browse files

Merge branch 'nico-dev' into 'main'

First merge from the `nico-dev` branch.

See merge request !1
parents 7e296fae 6e919954
No related branches found
No related tags found
2 merge requests!2Main,!1First merge from the `nico-dev` branch.
Pipeline #139508 failed
{"id" : "05a9e204-40d4-446d-8a70-f4afda6e48c7", "mdFormat" : "MMD Simple", "Username" : "thomz", "Institute" : "MPCDF", "Department" : "", "Group" : "", "Project" : "", "Contributors" : "", "Date" : "2022-07-21", "Name" : "", "Description" : "", "Homepage" : "", "Target" : "", "Storage" : "", "Format" : "", "Size" : "", "Comment" : ""}
\ No newline at end of file
{"id" : "05a9e204-40d4-446d-8a70-f4afda6e48c7", "mdFormat" : "MMD Simple", "Username" : "thomz", "Institute" : "MPCDF", "Department" : "", "Group" : "", "Project" : "", "Contributors" : "", "Date" : "2022-07-21", "Name" : "mmd", "Description" : "", "Homepage" : "", "Target" : "", "Storage" : "", "Format" : "", "Size" : "", "Comment" : ""}
import json
import ckan_editor_utils
import os
import argparse
infile = open("metadata.mmd", "r")
parser = argparse.ArgumentParser()
parser.add_argument(
"-i",
"--input",
help="A data file following the MMD Metadata.",
default="metadata.mmd",
required=False,
)
parser.add_argument(
"-c",
"--ckan",
help="The url of the CKAN instance.",
default="https://reptor.mpcdf.mpg.de/api/action/",
required=False,
)
data = json.load(infile)
args = parser.parse_args()
print("Arguments: " + str(args))
with open(args.input, "r") as f:
mmd_data = json.load(f)
print("Found metadata:")
for key, value in data.items():
print(key + ": " + value)
extras = []
for key, value in mmd_data.items():
print(key + ": " + value)
# Dataset ID necessary just for updating datasets, not for creating them
if key != "id":
item = {}
item["key"] = key
item["value"] = value
extras.append(item)
extras_dict = {}
extras_dict["extras"] = extras
print("Now creating CKAN dataset:")
url = 'https://reptor.mpcdf.mpg.de/api/action/'
api_key = os.environ.get('CKAN_API_KEY')
ckan_data = {}
ckan_data["title"] = mmd_data["Name"]
# Removing "Name" key because it is the same as the "title" key and brings confusion with the "name" key.
mmd_data.pop("Name")
ckan_data["name"] = ckan_data["title"].lower().replace(" ", "-")
ckan_data["owner_org"] = "mpcdf"
dataset_id = data["id"]
res_create = ckan_editor_utils.package_create(url, api_key, {"title" : data["Name"], "name" : data["Name"].lower().replace(" ", "-"), 'extra:identifier': data["id"], 'notes': data["Description"], 'author' : data["Username"], 'owner_org': 'mpcdf'})
print("Return code: ", res_create)
url = args.ckan
api_key = os.environ.get("CKAN_API_KEY")
res_create = ckan_editor_utils.package_create(
url,
api_key,
{**extras_dict, **ckan_data}
# {
# "title": data["Name"],
# "name": data["Name"].lower().replace(" ", "-"),
# "extra:identifier": data["id"],
# "notes": data["Description"],
# "author": data["Username"],
# "owner_org": "mpcdf",
# },
)
print("Return code: ", res_create)
print(res_create.json())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment