Esempio n. 1
0
    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)
from pyDataverse.api import Api
import json
import dvconfig
base_url = dvconfig.base_url
api_token = dvconfig.api_token
api = Api(base_url, api_token)
print(api.status)
dataset_json = 'data/dataverses/open-source-at-harvard/datasets/open-source-at-harvard/open-source-at-harvard.json'
with open(dataset_json) as f:
    metadata = json.load(f)
dataverse = 'open-source-at-harvard'
resp = api.create_dataset(dataverse, json.dumps(metadata))
print(resp)
dataset_pid = resp.json()['data']['persistentId']
tabular_file = 'data/dataverses/open-source-at-harvard/datasets/open-source-at-harvard/files/2019-02-25.tsv'
resp = api.upload_file(dataset_pid, tabular_file)
print(resp)