diff --git a/python/create_dataset/create_dataset.py b/python/create_dataset/create_dataset.py new file mode 100644 index 0000000..c3e2b23 --- /dev/null +++ b/python/create_dataset/create_dataset.py @@ -0,0 +1,42 @@ +import json +import os +import sys + +from pyDataverse.api import NativeApi + +try: + base_url=os.environ['BASE_URL'] + print("Using base URL from $BASE_URL.") +except: + print("You must define a BASE_URL environment variable.") + exit(1) + +try: + api_token=os.environ['API_TOKEN'] + print("Using API token from $API_TOKEN.") +except: + print("You must define a API_TOKEN environment variable.") + exit(1) + +try: + collection=os.environ['COLLECTION'] + print("Using collection (dataverse) from $COLLECTION.") +except: + print("You must define a COLLECTION environment variable.") + exit(1) + +if len(sys.argv) < 2: + print("Usage: python create_dataset.py ") + exit(1) + +json_file = sys.argv[1] +with open(json_file, 'r') as f: + json_in = json.load(f) + +api = NativeApi(base_url, api_token) +print("Printing version of Dataverse") +print(api.get_info_version().json()) + +print("Creating a dataset in collection " + collection) +resp = api.create_dataset(collection, json_in, publish=False) +print(resp.json()) diff --git a/python/create_dataset/dataset-finch1.json b/python/create_dataset/dataset-finch1.json new file mode 100644 index 0000000..433ea75 --- /dev/null +++ b/python/create_dataset/dataset-finch1.json @@ -0,0 +1,81 @@ +{ + "datasetVersion": { + "license": { + "name": "CC0 1.0", + "uri": "http://creativecommons.org/publicdomain/zero/1.0" + }, + "metadataBlocks": { + "citation": { + "fields": [ + { + "value": "Darwin's Finches", + "typeClass": "primitive", + "multiple": false, + "typeName": "title" + }, + { + "value": [ + { + "authorName": { + "value": "Finch, Fiona", + "typeClass": "primitive", + "multiple": false, + "typeName": "authorName" + }, + "authorAffiliation": { + "value": "Birds Inc.", + "typeClass": "primitive", + "multiple": false, + "typeName": "authorAffiliation" + } + } + ], + "typeClass": "compound", + "multiple": true, + "typeName": "author" + }, + { + "value": [ + { "datasetContactEmail" : { + "typeClass": "primitive", + "multiple": false, + "typeName": "datasetContactEmail", + "value" : "finch@mailinator.com" + }, + "datasetContactName" : { + "typeClass": "primitive", + "multiple": false, + "typeName": "datasetContactName", + "value": "Finch, Fiona" + } + }], + "typeClass": "compound", + "multiple": true, + "typeName": "datasetContact" + }, + { + "value": [ { + "dsDescriptionValue":{ + "value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", + "multiple":false, + "typeClass": "primitive", + "typeName": "dsDescriptionValue" + }}], + "typeClass": "compound", + "multiple": true, + "typeName": "dsDescription" + }, + { + "value": [ + "Medicine, Health and Life Sciences" + ], + "typeClass": "controlledVocabulary", + "multiple": true, + "typeName": "subject" + } + ], + "displayName": "Citation Metadata" + } + } + } +} diff --git a/python/create_dataset/requirements.txt b/python/create_dataset/requirements.txt new file mode 100644 index 0000000..de3dcfb --- /dev/null +++ b/python/create_dataset/requirements.txt @@ -0,0 +1 @@ +pyDataverse==0.3.5