Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions python/create_dataset/create_dataset.py
Original file line number Diff line number Diff line change
@@ -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 <json_file>")
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())
81 changes: 81 additions & 0 deletions python/create_dataset/dataset-finch1.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
1 change: 1 addition & 0 deletions python/create_dataset/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyDataverse==0.3.5