Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jun 26, 2018
1 parent 6baad69 commit 3859bdc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
32 changes: 17 additions & 15 deletions pyzenodo3/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BASE_URL = "https://zenodo.org/api"
HDR = {"Content-Type": "application/json"}


def meta(inifn: Path) -> Path:
""" creates metadata for Zenodo upload.
1. create dict() with metadata
Expand Down Expand Up @@ -72,7 +73,7 @@ def get_token(token: Union[str, Path]) -> str:

def upload_meta(token: str, metafn: Path, depid: str):
"""upload metadata to zenodo"""

if not metafn:
raise ValueError('must specify API token or file containing the token')

Expand All @@ -84,39 +85,40 @@ def upload_meta(token: str, metafn: Path, depid: str):
meta = metafn.read_text()

r = requests.put(f"{BASE_URL}/deposit/depositions/{depid}",
params={'access_token': token},
data=meta, #json.dumps(meta),
headers=HDR)
params={'access_token': token},
data=meta, # json.dumps(meta),
headers=HDR)

if r.status_code != 200:
raise requests.HTTPError(f"Error in metadata upload, status code: {r.status_code} {r.json()['message']}")


def upload_data(token: str, datafn: Path, depid: str):

r = requests.post(f"{BASE_URL}/deposit/depositions/{depid}/files",
params={'access_token': token},
data={'filename': str(datafn)},
data={'filename': str(datafn)},
files={'file': datafn.open('rb')})

if r.status_code != 201:
raise requests.HTTPError(f"Error in data upload, status code: {r.status_code} {r.json()['message']}")

print(f"{datafn} ID = {depid} (DOI: 10.5281/zenodo.{depid})")


def create(token: str) -> str:
r = requests.post(f"{BASE_URL}/deposit/depositions",

r = requests.post(f"{BASE_URL}/deposit/depositions",
params={'access_token': token},
json={},
json={},
headers=HDR)

if r.status_code != 201:
raise requests.HTTPError(f"Error in creation, status code: {r.status_code} {r.json()['message']}")
# %% Get the deposition ID
return r.json()["id"]


def upload(metafn: Path, datafn: Path, token: Union[str, Path]):
"""takes metadata and file and uploads to Zenodo"""

Expand All @@ -132,4 +134,4 @@ def upload(metafn: Path, datafn: Path, token: Union[str, Path]):
# %% Upload data
upload_data(token, datafn, depid)
# %% add metadata
# upload_meta(token, metafn, depid)
# upload_meta(token, metafn, depid)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[metadata]
name = pyzenodo3
version = 0.1.0
version = 0.1.1
author = Michael Hirsch, Tom Klaver
description = Pure Python 3 wrapper for the Zenodo REST API
long_description = file: README.md
Expand Down
4 changes: 2 additions & 2 deletions upload_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main():

metafn = zup.meta(p.inifn)
zup.upload(metafn, p.path, p.apikey)


if __name__ == '__main__':
main()

0 comments on commit 3859bdc

Please sign in to comment.