Commit 4860cb61 authored by Kruisselbrink, Johannes's avatar Kruisselbrink, Johannes
Browse files

Update python download tools to allow for easier download of data sources

parent fff07f46
......@@ -10,7 +10,7 @@ import keyring
# input parameters
default_mcra_url = 'https://mcra.test.wur.nl/Mcra90'
default_mcra_url = 'https://mcra.test.wur.nl/Mcra91'
parser = ArgumentParser(
description=
......
......@@ -9,7 +9,7 @@ import keyring
# input parameters
default_mcra_url = 'https://mcra.test.wur.nl/Mcra90'
default_mcra_url = 'https://mcra.test.wur.nl/Mcra91'
parser = ArgumentParser(
description=
......@@ -54,10 +54,16 @@ else:
mcrausername = args.username
if args.keyring is None:
mcrapassword=getpass.getpass("MCRA Password:").strip()
mcrapassword = getpass.getpass("MCRA Password:").strip()
else:
mcrapassword = keyring.get_password(args.keyring, mcrausername)
if args.id is None:
print("Data source version id:")
datasourceid = input().strip()
else:
datasourceid = args.id
# This is the call to set-up the api
api = WebApiClient.Mcra(
url=args.apiurl,
......@@ -67,4 +73,4 @@ api = WebApiClient.Mcra(
if args.verbosity >= 1:
print('Downloading {file}'.format(file=args.filename))
api.get_file(id=args.id, filename=args.filename)
\ No newline at end of file
api.get_file(id=datasourceid, filename=args.filename)
\ No newline at end of file
......@@ -10,7 +10,7 @@ import keyring
# input parameters
default_mcra_url = 'https://mcra.test.wur.nl/Mcra90'
default_mcra_url = 'https://mcra.test.wur.nl/Mcra91'
parser = ArgumentParser(
description=
......
......@@ -10,7 +10,7 @@ import keyring
# input parameters
default_mcra_url = 'https://mcra.test.wur.nl/Mcra90'
default_mcra_url = 'https://mcra.test.wur.nl/Mcra91'
parser = ArgumentParser(
description=
......
......@@ -59,6 +59,11 @@ class Mcra:
else:
return result
def get_datasource_version(self, id=None):
result = self.__call_api__(
apiCall=f'DataSources/GetVersion/{id}').json()
return result
def get_workspace(self, id=None):
if id is None:
result = self.__call_api__(
......@@ -81,6 +86,10 @@ class Mcra:
result = self.__call_api__(
apiCall=f'DataSources/DownloadVersion/{id}')
if filename is None:
dsinfo = self.get_datasource_version(id)
filename = dsinfo['name']
with open(filename, 'wb') as fd:
for chunk in result.iter_content(chunk_size=128):
fd.write(chunk)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment