Skip to content

Commit

Permalink
[add] some minimal metainformation about the record
Browse files Browse the repository at this point in the history
  • Loading branch information
dvolgyes committed Jun 8, 2018
1 parent 31d5cdd commit b511b65
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setuptools.setup(
name='zenodo_get',
version='1.0.0',
version='1.0.1',
author='David Volgyes',
author_email='david.volgyes@ieee.org',
description=short_description,
Expand Down
52 changes: 38 additions & 14 deletions src/zenodo_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import wget
import time

__version__ = '1.0.0'

__version__ = '1.0.1'
__title__ = 'zenodo_get'
__summary__ = 'Zenodo record downloader.'
__uri__ = 'https://gitlab.com/dvolgyes/zenodo_get'
Expand All @@ -24,17 +25,17 @@
on the Zenodo record ID or the DOI. The primary goal is to easy access
to large records with dozens of files.
"""
__bibtex__ = """@misc{david_volgyes_2018_1261812,
__bibtex__ = """@misc{david_volgyes_2018_""" + __doi__ + """,
author = {David Völgyes},
title = {Zenodo_get: a downloader for Zenodo records.},
month = june,
year = 2018,
doi = {%s},
url = {https://doi.org/%s}
}""" % (__doi__, __doi__)
doi = {""" + __doi__ + """},
url = {https://doi.org/""" + __doi__ + """}
}"""
__reference__ = """David Völgyes. (2018, June 4). \
Zenodo_get: a downloader for Zenodo records (Version %s).
Zenodo. https://doi.org/%s""" % (__version__, __doi__)
Zenodo_get: a downloader for Zenodo records (Version """ + __version__ + """).
Zenodo. https://doi.org/""" + __doi__


def eprint(*args, **kwargs):
Expand All @@ -59,9 +60,9 @@ def check_hash(filename, checksum):
if __name__ == '__main__':

parser = OptionParser(
usage='%prog [options] RECORD_OR_DOI',
version='%prog {}'.format(__version__)
)
usage='%prog [options] RECORD_OR_DOI',
version='%prog {}'.format(__version__)
)

parser.add_option('-c', '--cite',
dest='cite',
Expand Down Expand Up @@ -132,6 +133,13 @@ def check_hash(filename, checksum):
help='Wait N second before retry attempt, e.g. 0.5',
default=0.5)

parser.add_option('-t', '--time-out',
action='store',
type=float,
dest='timeout',
help='Set connection time-out. Default: 15 [sec].',
default=15.)

(options, args) = parser.parse_args()

if options.cite:
Expand All @@ -157,9 +165,12 @@ def check_hash(filename, checksum):
if not url.startswith('http'):
url = 'https://doi.org/'+url
try:
r = requests.get(url)
except:
eprint('Connection error. Please, check the DOI/ID, and try again later.')
r = requests.get(url, timeout=options.timeout)
except requests.exceptions.ConnectTimeout:
eprint('Connection timeout.')
sys.exit(1)
except Exception:
eprint('Connection error.')
sys.exit(1)
if not r.ok:
eprint('DOI could not be resolved. Try again, or use record ID.')
Expand All @@ -170,7 +181,15 @@ def check_hash(filename, checksum):
recordID = recordID.strip()

url = 'https://zenodo.org/api/records/'
r = requests.get(url+recordID)
try:
r = requests.get(url+recordID, timeout=options.timeout)
except requests.exceptions.ConnectTimeout:
eprint('Connection timeout during metadata reading.')
sys.exit(1)
except Exception:
eprint('Connection error during metadata reading.')
sys.exit(1)

if r.ok:
js = json.loads(r.text)
files = js['files']
Expand All @@ -194,7 +213,12 @@ def check_hash(filename, checksum):
link = f['links']['self']
wgetfile.write('{}\n'.format(link,))
else:
eprint('Title: {}'.format(js['metadata']['title']))
eprint('Keywords: '+(', '.join(js['metadata']['keywords'])))
eprint('Publication date: '+js['metadata']['publication_date'])
eprint('DOI: '+js['metadata']['doi'])
eprint('Total size: {:.1f} MB'.format(total_size/2**20,))

for f in files:
link = f['links']['self']
size = f['size']/2**20
Expand Down

0 comments on commit b511b65

Please sign in to comment.