Mercurial > repos > stevecassidy > alveoimport
diff alveo_api_key.py @ 0:bfe39bd252df draft
planemo upload commit 5de43e6a614de2a1b2065bc63823ecc9854ebb32-dirty
author | stevecassidy |
---|---|
date | Mon, 18 Jul 2016 23:49:40 -0400 |
parents | |
children | 7b6021997b8e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/alveo_api_key.py Mon Jul 18 23:49:40 2016 -0400 @@ -0,0 +1,44 @@ +from __future__ import print_function +import argparse +import pyalveo +import sys + +API_URL = 'https://app.alveo.edu.au' + +def parser(): + parser = argparse.ArgumentParser(description="Retrieves Alveo Item Lists") + parser.add_argument('--api_key', required=True, action="store", type=str, help="Alveo API key") + parser.add_argument('--output_path', required=True, action="store", type=str, help="File to store the API key in") + return parser.parse_args() + +def write_key(api_key, output_path, client_module=pyalveo): + """Tests whether an API key is valid and writes it to a file. + + :type api_key: String + :param api_key: Alveo API key + + :type output_path: String + :param output_path: Path to the file to store the API key in + + :type client_module: pyalveo.Client + :param client_module: Module providing the client (used for testing purposes), + defaults to pyalveo + + :raises: pyalveo.APIError if the API request is not successful + + """ + client = client_module.Client(api_key, API_URL) + outfile = open(output_path, 'w') + outfile.write(api_key) + outfile.close() + +def main(): + args = parser() + try: + write_key(args.api_key, args.output_path) + except Exception as e: + print("ERROR: " + str(e), file=sys.stderr) + sys.exit(1) + +if __name__ == '__main__': + main() \ No newline at end of file