def result_types(job_id): url = IPS_URL + '/resulttypes/' + job_id r = get(url=url, params=None, response_format='xml') root = ElementTree.fromstring(r.text) types = root.findall('type') r = {x.find('identifier').text: { 'Accept': x.find('mediaType').text} for x in types} return r
def brew_get(package, os, platform, dnld_dir): url_mac = 'https://formulae.brew.sh/api/formula/{}.json' url_linux = 'https://formulae.brew.sh/api/formula-linux/{}.json' if os == 'mac': if platform == 'Big Sur': platform = 'big_sur' elif platform == 'Catalina': platform = 'catalina' elif platform == 'Mojave': platform = 'mojave' elif platform == 'High Sierra': platform = 'high_sierra' elif platform == 'Sierra': platform = 'sierra' elif platform == 'El Capitan': platform = 'el_capitan' elif platform == 'Yosemite': platform = 'yosemite' else: return None url = url_mac.format(package) if os == 'linux': if platform == 'linux': platform = 'x86_64_linux' else: return None url = url_linux.format(package) r = get(url) try: r.raise_for_status() except Exception as e: print(e) return None data = r.json() version = data['versions']['stable'] dnld_dir = abspath(expanduser(dnld_dir)) file_url = data['bottle']['stable']['files'][platform]['url'] file_name = file_url.split('/')[-1] dnld_path = opj(dnld_dir, file_name) download_file(file_url, dnld_path) return dnld_path, version
def status(job_id): # Possible response values: # # RUNNING: the job is currently being processed. # FINISHED: job has finished, and the results can then be retrieved. # ERROR: an error occurred attempting to get the job status. # FAILURE: the job failed. # NOT_FOUND: the job cannot be found. url = IPS_URL + '/status/' + job_id r = get(url=url, params=None, response_format='text') job_status = r.text return job_status
def fasta_by_accession_list(acc_list): url = PROT_API_URL + '/proteins' max_recs = 90 pages = int(ceil(len(acc_list) / max_recs)) data = '' for p in range(pages): offset = p * max_recs last = offset + max_recs acc_param = ','.join(x for x in acc_list[offset:last]) params = {'accession': acc_param} response = get(url=url, params=params, response_format='fasta') if response is None: response = '' data = data + response.text return data
def _result(job_id, result_type): available_result_types = result_types(job_id) if result_type in available_result_types: response_format = available_result_types[result_type] else: # raise Exception # ToDo: Just skips if, for some reason, the server # did not report an error but also did not # return anything. # I noticed that in these cases waiting a little and retrying # sometimes works. Should implement wait and retry in this # function. return None url = IPS_URL + '/result/' + job_id + '/' + result_type response = get(url=url, params=None, response_format=response_format) # Returns unparsed response! return response
def test_get_retry_fail(self): try: r = get(url='http://httpbin.org/status/500', response_format='text') except RetryError as e: pass
def test_get_eventual_success(self): r = get(url='http://httpbin.org/status/200,200,500', response_format='text') assert r.status_code == 200