__init__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:enasearch 作者: bebatut 项目源码 文件源码
def request_url(url, display, file=None):
    """Run the URL request and return content or status

    This function tooks an URL built to query or extract data from ENA and apply
    this URL. If a filepath is given, the function puts the result into the
    file and returns the status of the request. Otherwise, the results of the
    request is returned by the function in different format depending of the
    display format

    :param url: URL to request on ENA
    :param display: display option
    :param length: number of records to retrieve
    :param file: filepath to save the content of the search

    :return: status of the request or the result of the request (in different format)
    """
    if file is not None:
        r = requests.get(url, stream=True)
        r.raise_for_status()
        with open(file, "wb") as fd:
            for chunk in r.iter_content(chunk_size=128):
                fd.write(chunk)
        return r.raise_for_status()
    else:
        r = requests.get(url)
        r.raise_for_status()
        if display == "xml":
            return xmltodict.parse(r.text)
        elif display == "fasta" or display == "fastq":
            return format_seq_content(r.text, display)
        else:
            return r.text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号