Mercurial > repos > stevecassidy > alveoimport
comparison alveo_item_list_importer.py @ 14:a38315ecf593 draft
planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
author | stevecassidy |
---|---|
date | Wed, 01 Nov 2017 01:18:15 -0400 |
parents | 56fda3d161f0 |
children |
comparison
equal
deleted
inserted
replaced
13:be3fd14899a1 | 14:a38315ecf593 |
---|---|
1 from __future__ import print_function | 1 from __future__ import print_function |
2 import json | |
3 import argparse | 2 import argparse |
4 import pyalveo | |
5 import sys | 3 import sys |
6 | 4 from util import get_item_lists |
7 API_URL = 'https://app.alveo.edu.au' # TODO: export constants to a separate module | |
8 | 5 |
9 | 6 |
10 def parser(): | 7 def parser(): |
11 parser = argparse.ArgumentParser(description="Retrieves Alveo Item Lists") | 8 p = argparse.ArgumentParser(description="Retrieves Alveo Item Lists") |
12 parser.add_argument('--api_key', required=True, action="store", type=str, help="Alveo API key") | 9 p.add_argument('--api_key', required=True, action="store", type=str, help="Alveo API key") |
13 parser.add_argument('--output', required=True, action="store", type=str, help="Path to output file") | 10 p.add_argument('--output', required=True, action="store", type=str, help="Path to output file") |
14 return parser.parse_args() | 11 return p.parse_args() |
15 | 12 |
16 # TODO: export common function to helper module | |
17 def get_item_lists(api_key): | |
18 client = pyalveo.Client(api_key=api_key, api_url=API_URL, use_cache=False) | |
19 return client.get_item_lists() | |
20 | 13 |
21 def write_table(item_lists, filename): | 14 def write_table(item_lists, filename): |
22 with open(filename, 'w') as outfile: | 15 with open(filename, 'w') as outfile: |
23 for list_set in item_lists.values(): | 16 for list_set in item_lists.values(): |
24 for item_list in list_set: | 17 for item_list in list_set: |
25 outfile.write("%s (%d)\t%s\n" % (item_list['name'], item_list['num_items'], item_list['item_list_url'])) | 18 outfile.write("%s (%d)\t%s\n" % (item_list['name'], item_list['num_items'], item_list['item_list_url'])) |
19 | |
26 | 20 |
27 def main(): | 21 def main(): |
28 args = parser() | 22 args = parser() |
29 try: | 23 try: |
30 api_key = open(args.api_key, 'r').read().strip() | 24 api_key = open(args.api_key, 'r').read().strip() |