Mercurial > repos > earlhaminst > ensembl_get_sequences
diff get_feature_info.py @ 4:3b686142e9c2 draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/Ensembl-REST commit 95bab1105cf8a7b07c668f08f712399e8775a4ae
author | earlhaminst |
---|---|
date | Fri, 13 Apr 2018 09:43:51 -0400 |
parents | 4b7261f484bb |
children | 0fa1d1cc417d |
line wrap: on
line diff
--- a/get_feature_info.py Fri Mar 24 11:57:48 2017 -0400 +++ b/get_feature_info.py Fri Apr 13 09:43:51 2018 -0400 @@ -4,6 +4,7 @@ import json import optparse +from itertools import islice import requests from six.moves.urllib.parse import urljoin @@ -31,13 +32,27 @@ headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} params = dict((k, getattr(options, k)) for k in ['format', 'expand']) + +first = True + +print('{') + with open(options.input) as f: - ids = [line.strip() for line in f] -data = {'ids': ids} -r = requests.post(urljoin(server, ext), params=params, headers=headers, - data=json.dumps(data)) + while True: + ids = [line.strip() for line in islice(f, 50)] + if not ids: + break + if not first: + print(",") + data = {'ids': ids} + r = requests.post(urljoin(server, ext), params=params, headers=headers, + data=json.dumps(data)) -if not r.ok: - r.raise_for_status() + if not r.ok: + r.raise_for_status() -print(r.text) + print(r.text[1:-1]) + + first = False + +print('}')