Exemplo n.º 1
0
def get_doi(metadata, doi=None, production=False):
    """ Use datacite to get DOI for metadata
    """

    # development
    dcprefix_dev = '10.22013'
    dcurl_dev = 'http://doi.test.datacite.org'
    # production
    dcprefix_prod = '10.25800'
    dcurl_prod = 'http://doi.datacite.org'

    if production:
        url = dcurl_prod
        prefix = dcprefix_prod
    else:
        url = dcurl_dev
        prefix = dcprefix_dev

    # either generate doi or fix doi without prefix
    if doi is not None:
        if prefix not in doi:
            print(
                f'DOI provided ({doi}) does not have required prefix ({prefix}). Adding prefix.'
            )
            doi = prefix + '/' + doi
    else:
        d = DataCiteRESTClient(username='******',
                               password=dcp,
                               prefix=prefix,
                               test_mode=(not production))
        doi = d.public_doi(metadata, url)

    return doi
Exemplo n.º 2
0
    def __init__(self,
                 client,
                 pid_type="doi",
                 default_status=PIDStatus.NEW,
                 generate_id_func=None,
                 generate_doi_func=None,
                 **kwargs):
        """Constructor."""
        self.client = client
        self.api_client = None
        self.is_api_client_setup = False

        if client and client.has_credentials():
            self.api_client = DataCiteRESTClient(client.username,
                                                 client.password,
                                                 client.prefix,
                                                 client.test_mode)
            self.is_api_client_setup = True

        super().__init__(self.api_client, pid_type, default_status)

        self.generate_id = generate_id_func or \
            DOIDataCitePIDProvider._generate_id

        default_generate_doi = self._generate_doi
        format_func = current_app.config['RDM_RECORDS_DOI_DATACITE_FORMAT']
        if format_func and callable(format_func):
            default_generate_doi = format_func
        self.generate_doi = generate_doi_func or default_generate_doi
Exemplo n.º 3
0
def get_rest(username="******", password="******",
             test_mode=True, timeout=None):
    """Create a API client."""
    return DataCiteRESTClient(
        username=username,
        password=password,
        test_mode=test_mode,
        timeout=timeout,
    )
Exemplo n.º 4
0
 def api(self):
     """DataCite REST API client instance."""
     if self._api is None:
         self.check_credentials()
         self._api = DataCiteRESTClient(
             self.cfg('username'),
             self.cfg('password'),
             self.cfg('prefix'),
             self.cfg('test_mode', True),
         )
     return self._api
Exemplo n.º 5
0
def get_rest(username="******", password="******", prefix='10.1234',
             with_fake_url=True):
    """Create a REST API client."""
    client = DataCiteRESTClient(
        username=username,
        password=password,
        prefix=prefix,
        test_mode=True,
    )
    if with_fake_url:
        # change URL for tests
        client.api_url = RESTURL
    return client
Exemplo n.º 6
0
    def __init__(self,
                 name,
                 client,
                 pid_type="doi",
                 default_status=PIDStatus.NEW,
                 **kwargs):
        """Constructor."""
        self._client_credentials = client
        self.client = DataCiteRESTClient(client.username, client.password,
                                         client.prefix, client.test_mode)

        super(DataCiteProvider, self).__init__(name, client, pid_type,
                                               default_status)
Exemplo n.º 7
0
def get_rest(username="******",
             password="******",
             prefix='10.5072',
             test_mode=False,
             timeout=None):
    """Create a REST API client."""
    return DataCiteRESTClient(
        username=username,
        password=password,
        prefix=prefix,
        url=RESTURL,
        test_mode=test_mode,
        timeout=timeout,
    )
Exemplo n.º 8
0
    def __init__(self,
                 client,
                 pid_type="doi",
                 default_status=PIDStatus.NEW,
                 generate_suffix_func=None,
                 generate_id_func=None,
                 **kwargs):
        """Constructor."""
        self.client = client
        self.api_client = DataCiteRESTClient(client.username, client.password,
                                             client.prefix, client.test_mode)

        super().__init__(self.api_client, pid_type, default_status)

        self.generate_suffix = generate_suffix_func or \
            DOIDataCitePIDProvider._generate_suffix
        self.generate_id = generate_id_func or self._generate_id
                if args.prefix != None:
                    prefix = args.prefix
                else:
                    prefix = "10.7907"

                # Get our DataCite password
                infile = open("pw", "r")
                password = infile.readline().strip()

                if args.test == True:
                    # Existing test record
                    record_number = 5756
                    d = DataCiteRESTClient(
                        username="******",
                        password=password,
                        prefix="10.33569",
                        test_mode=True,
                    )
                    repo_url = "http://authorstest.library.caltech.edu"
                else:
                    d = DataCiteRESTClient(
                        username="******",
                        password=password,
                        prefix="10.7907",
                    )
                    repo_url = "https://authors.library.caltech.edu"

                # Command line option sets DOI
                if args.doi:
                    if "doi" in eprint:
                        print(
            r = requests.get(next_link)
            data = r.json()
            for doi in data["data"]:
                item_url = doi["attributes"]["url"]
                if "http://resolver.caltech.edu" in item_url:
                    links[doi["id"]] = item_url
            if "next" in data["links"]:
                next_link = data["links"]["next"]
            else:
                next_link = None
    return links


if __name__ == "__main__":
    prefix = "10.26206"

    # DataCite Setup
    d = DataCiteRESTClient(
        username="******",
        password="",
        prefix=prefix,
    )

    client_ids = ["caltech.library"]
    links = get_datacite_dois(client_ids)
    for l in progressbar(links):
        if l.split("/")[0] == prefix:
            print(l)
            new_link = links[l].replace("http://", "https://")
            d.update_url(l, new_link)
Exemplo n.º 11
0
        {'name': 'Smith, John'},
    ],
    'titles': [
        {'title': 'Minimal Test Case', }
    ],
    'publisher': 'Invenio Software',
    'publicationYear': '2015',
    'types': {
        'resourceType': 'Dataset',
        'resourceTypeGeneral': 'Dataset'
    },
    'schemaVersion': 'http://datacite.org/schema/kernel-4',
}

# Validate dictionary
assert schema42.validate(data)

# Generate DataCite XML from dictionary.
doc = schema42.tostring(data)

# Initialize the REST client.
d = DataCiteRESTClient(
    username="******",
    password="******",
    prefix="10.1234",
    test_mode=True
)

# Reserve a draft DOI
doi = d.draft_doi()
Exemplo n.º 12
0
    },
    'schemaVersion': 'http://datacite.org/schema/kernel-4',
}

# Validate dictionary
assert schema42.validate(data)

# Generate DataCite XML from dictionary.
doc = schema42.tostring(data)

# Initialize the REST client.
username = os.environ["DATACITE_USER"]
password = os.environ["DATACITE_PW"]
prefix = os.environ["DATACITE_PREFIX"]
d = DataCiteRESTClient(username=username,
                       password=password,
                       prefix=prefix,
                       test_mode=True)

# Reserve a draft DOI
doi = d.draft_doi()

# Mint new DOI
#d.doi_post('10.5072/test-doi', 'http://example.org/test-doi')

# Get DOI location
#location = d.doi_get(doi)

# Set alternate URL for content type (available through api)
#d.media_post(
#    "10.5072/test-doi",
#    {"application/json": "http://example.org/test-doi/json/",