def create(self, title): ''' Create a draft in Dataverse with some minimal metadata. ''' if self.draftUrl != '': print "Draft already created: " + self.draftUrl return [ 'Dataverse PUBLISH INFO: Draft already exists: ' + self.draftUrl ] connection = Connection(self.apiUrl, self.apiToken, use_https=False) dataverse = connection.get_dataverse(self.alias) #create draft #put some required default metadata creator = 'ibridges' description = 'Description' metadata = {'subject': 'Other'} try: self.__dataset = dataverse.create_dataset(title=title, creator=creator, description=description, **metadata) self.__md = self.__dataset.get_metadata() self.draftUrl = 'http://'+self.__dataset.connection.host+'/dataset.xhtml?persistentId='+\ self.__dataset.doi return except: return ["Draft not created."]
def create(self, title): ''' Create a draft in Dataverse with some minimal metadata. ''' if self.draftUrl != '': raise RuntimeError("Dataverse PUBLISH:" + "Draft already created: " + self.draftUrl) self.logger.debug('connect to %s', self.apiUrl) connection = Connection(self.apiUrl, self.apiToken, use_https=False) dataverse = connection.get_dataverse(self.alias) # create draft # put some required default metadata creator = 'ibridges' description = 'Description' metadata = {'subject': 'Other'} self.logger.info('create draft title=%s, creator=%s, description=%s' % (title, creator, description)) self.__dataset = dataverse.create_dataset(title=title, creator=creator, description=description, **metadata) self.__md = self.__dataset.get_metadata() self.draftUrl = 'http://' + self.__dataset.connection.host + \ '/dataset.xhtml?persistentId=' + \ self.__dataset.doi self.logger.info('draft created: %s', self.draftUrl)
def connect(username, password, host=settings.HOST): connection = Connection( username=username, password=password, host=host, disable_ssl=not settings.VERIFY_SSL, ) return connection if connection.connected else None
def connect_or_403(username, password, host=settings.HOST): connection = Connection( username=username, password=password, host=host, disable_ssl=not settings.VERIFY_SSL, ) if connection.status == http.FORBIDDEN: raise HTTPError(http.FORBIDDEN) return connection if connection.connected else None
#cd /home/admincentos/src/dataverse from dataverse import Connection from dataverse.dataverse import Dataverse from dataverse.dataset import Dataset from dataverse import utils import uuid import requests #Create connection to dataverse host = 'demo.dataverse.nl' # Instance at DANS token = '********' connection = Connection(host, token, use_https=False) alias = 'myDataverseAlias' # Create Dataverse dataverse = connection.create_dataverse(alias, alias, '*****@*****.**', alias) # Http responses on server malformatted: https:// ... 8080:8080 or 8181:8181 --> server side fault, github issue created #if connection.host.endswith(':8080') and connection.host != 'localhost': # href = dataverse.collection.get('href') # href = href.replace('https', 'http') # href = href.replace('8080:8080', '8080') # dataverse.collection.set('href', href) # and publish dataverse.publish() # Get dataverse and data dataverse = connection.get_dataverse(alias) datasets = dataverse.get_datasets( ) # throws error Failed to parse: ip.add.ress:8080:8080 dataset = dataverse.get_dataset_by_doi(dataverse.get_datasets()[0].doi)
from config import configuration def loadjson(apiurl): jsondataurl = apiurl req = urllib2.Request(jsondataurl) opener = urllib2.build_opener() f = opener.open(req) dataframe = simplejson.load(f) return dataframe config = configuration() connection = Connection(host, token) dataverse = connection.get_dataverse('clioinfra') for item in dataverse.get_contents(): # u'protocol': u'hdl', u'authority': u'10622' u'identifier': u'R8EJJF' try: handle = str(item['protocol']) + ':' + str( item['authority']) + "/" + str(item['identifier']) datasetid = item['id'] url = "https://" + str(host) + "/api/datasets/" + str( datasetid) + "/versions/1.0?&key=" + str(token) print item dataframe = loadjson(url) for fileitem in dataframe['data']['files']: runimport = os.path.abspath(os.path.join( os.path.dirname(__file__)))
def _get_connection(self): dvurl = self.host['url'] apikey = self.host['apikey'] dvurl = self.truncate_url(dvurl) c = Connection(dvurl, apikey) return c
def _connect(host, token): try: return Connection(host, token) except ConnectionError: return None
def _connect(token, host=settings.HOST): try: return Connection(host, token) except ConnectionError: return None