pull/704/head
Tom Morrell 2019-06-13 11:14:16 -07:00
rodzic 2db395ac87
commit 10fc5b5f36
2 zmienionych plików z 33 dodań i 21 usunięć

Wyświetl plik

@ -30,22 +30,22 @@ class Zenodo(ContentProvider):
return urlopen(req) return urlopen(req)
def _process_doi(self, doi): def _process_doi(self, doi):
#Transform a DOI to a URL # Transform a DOI to a URL
#If not a doi, assume we have a URL and return # If not a doi, assume we have a URL and return
if is_doi(doi): if is_doi(doi):
#Zenodo instances will most likely use DataCite DOIs # Zenodo instances will most likely use DataCite DOIs
#Could also resolve the DOI to get the url # Could also resolve the DOI to get the url
#Get url from DataCite # Get url from DataCite
doi = normalize_doi(doi) doi = normalize_doi(doi)
req = Request( req = Request(
"https://api.datacite.org/dois/{}".format(doi), "https://api.datacite.org/dois/{}".format(doi),
headers={"accept": "application/json"}, headers={"accept": "application/json"},
) )
resp = self._urlopen(req) resp = self._urlopen(req)
record = json.loads(resp.read().decode("utf-8")) record = json.loads(resp.read().decode("utf-8"))
url = record['data']['attributes']['url'] url = record["data"]["attributes"]["url"]
return url return url
else: else:
return doi return doi
@ -55,24 +55,36 @@ class Zenodo(ContentProvider):
# We need the hostname (url where records are), api url (for metadata), # We need the hostname (url where records are), api url (for metadata),
# filepath (path to files in metadata), filename (path to filename in # filepath (path to files in metadata), filename (path to filename in
# metadata), type (path to type in metadata) # metadata), type (path to type in metadata)
hosts = [{'hostname':["https://zenodo.org/record/","http://zenodo.org/record/"], hosts = [
'api':'https://zenodo.org/api/records/','filepath':"files", {
'filename':"files.key",'download':"links.download", "hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"],
'type':"metadata.upload_type"}, "api": "https://zenodo.org/api/records/",
{'hostname':["https://data.caltech.edu/records/","http://data.caltech.edu/records/"], "filepath": "files",
'api':"https://data.caltech.edu/api/record/",'filepath':"files", "filename": "files.key",
'filename':"electronic_location_and_access.electronic_name.0", "download": "links.download",
'type':"metadata.resourceType.resourceTypeGeneral"}] "type": "metadata.upload_type",
},
{
"hostname": [
"https://data.caltech.edu/records/",
"http://data.caltech.edu/records/",
],
"api": "https://data.caltech.edu/api/record/",
"filepath": "files",
"filename": "electronic_location_and_access.electronic_name.0",
"type": "metadata.resourceType.resourceTypeGeneral",
},
]
url = self._process_doi(doi) url = self._process_doi(doi)
resp = self._urlopen(url) resp = self._urlopen(url)
self.record_id = resp.url.rsplit("/", maxsplit=1)[1] self.record_id = resp.url.rsplit("/", maxsplit=1)[1]
for host in hosts: for host in hosts:
if any([url.startswith(s) for s in host['hostname']]): if any([url.startswith(s) for s in host["hostname"]]):
return {"record": self.record_id, "host": host} return {"record": self.record_id, "host": host}
def fetch(self, spec, output_dir, yield_output=False): def fetch(self, spec, output_dir, yield_output=False):
"""Fetch and unpack a Zenodo record""" """Fetch and unpack a Zenodo record"""
record_id = spec["record"] record_id = spec["record"]
@ -80,7 +92,7 @@ class Zenodo(ContentProvider):
yield "Fetching Zenodo record {}.\n".format(record_id) yield "Fetching Zenodo record {}.\n".format(record_id)
req = Request( req = Request(
"{}{}".format(host['api'],record_id), "{}{}".format(host["api"], record_id),
headers={"accept": "application/json"}, headers={"accept": "application/json"},
) )
resp = self._urlopen(req) resp = self._urlopen(req)

Wyświetl plik

@ -20,7 +20,7 @@ setup(
"ruamel.yaml>=0.15", "ruamel.yaml>=0.15",
"toml", "toml",
"semver", "semver",
"idutils" "idutils",
], ],
python_requires=">=3.5", python_requires=">=3.5",
author="Project Jupyter Contributors", author="Project Jupyter Contributors",