comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bfe39bd252df
1 from __future__ import print_function
2 import argparse
3 import pyalveo
4 import sys
5
6 API_URL = 'https://app.alveo.edu.au'
7
8 def parser():
9 parser = argparse.ArgumentParser(description="Retrieves Alveo Item Lists")
10 parser.add_argument('--api_key', required=True, action="store", type=str, help="Alveo API key")
11 parser.add_argument('--output_path', required=True, action="store", type=str, help="File to store the API key in")
12 return parser.parse_args()
13
14 def write_key(api_key, output_path, client_module=pyalveo):
15 """Tests whether an API key is valid and writes it to a file.
16
17 :type api_key: String
18 :param api_key: Alveo API key
19
20 :type output_path: String
21 :param output_path: Path to the file to store the API key in
22
23 :type client_module: pyalveo.Client
24 :param client_module: Module providing the client (used for testing purposes),
25 defaults to pyalveo
26
27 :raises: pyalveo.APIError if the API request is not successful
28
29 """
30 client = client_module.Client(api_key, API_URL)
31 outfile = open(output_path, 'w')
32 outfile.write(api_key)
33 outfile.close()
34
35 def main():
36 args = parser()
37 try:
38 write_key(args.api_key, args.output_path)
39 except Exception as e:
40 print("ERROR: " + str(e), file=sys.stderr)
41 sys.exit(1)
42
43 if __name__ == '__main__':
44 main()