def home_view(request, *args, **kwargs): if request.method == "POST": base_url = 'https://demo.dataverse.org' api_token = "bcd0d879-592d-425f-9547-a112eb367c17" api = Api(base_url, api_token=api_token) name = request.POST.get("dataverse") identifier = request.POST.get("identifier") dataverseType = request.POST.get("dataverseType") email = request.POST.get("email") metaData = '''{ "name": "''' + name + '''", "alias": "''' + identifier + '''", "dataverseContacts": [ { "contactEmail": "''' + email + '''" } ] }''' response = api.create_dataverse(identifier="khaled", metadata=metaData, auth=True) print(response.status_code) return render(request, "home.html", {})
if UPLOAD_DATA: CREATE_DV = False DELETE_DV = False CREATE_DS = False ADD_FILE = False DELETE_DS = False CREATE_DF = False api_token_up = os.environ["API_TOKEN_UP"] api_host_up = os.environ["API_HOST_UP"] api_up = Api(api_host_up, api_token=api_token_up, use_https=False) # create dataverse if CREATE_DV: dv_json = read_json_file( 'data/down/dv_AUSSDA/dv_AUSSDA_metadata.json') api_up.create_dataverse(dv_json['alias'], dict_to_json(dv_json)) time.sleep(0.2) # create dataset if CREATE_DS: ds_json = read_json_file( 'data/down/dv_AUSSDA/ds_VKYZPD/ds_VKYZPD_metadata.json') resp = api_up.create_dataset('science', dict_to_json(ds_json)) time.sleep(0.2) if ADD_FILE: doi = 'doi:10.5072/FK2/PF6EMS' filename = 'dev/cat.jpg' resp = api_up.upload_file(doi, filename)
else: dvtype = 'dataset' parent = parts[-4] if 'data' == parent: parent = ':root' if ('dataverse' == dvtype): print('Creating ' + dvtype + ' ' + json_file + ' in dataverse ' + parent) dv_json = path with open(dv_json) as f: metadata = json.load(f) print(metadata) # FIXME: Why is "identifier" required? identifier = metadata['alias'] resp = api.create_dataverse(identifier, json.dumps(metadata), parent=parent) print(resp) resp = api.publish_dataverse(identifier) print(resp) else: print('Creating ' + dvtype + ' ' + json_file + ' in dataverse ' + parent) dataset_json = path with open(dataset_json) as f: metadata = json.load(f) dataverse = parent resp = api.create_dataset(dataverse, json.dumps(metadata)) print(resp) dataset_pid = resp.json()['data']['persistentId'] dataset_dbid = resp.json()['data']['id']