utils.py 文件源码

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

项目:realtime-stock 作者: condereis 项目源码 文件源码
def request_quotes(tickers_list, selected_columns=['*']):
    """Request Yahoo Finance recent quotes.

    Returns quotes information from YQL. The columns to be requested are
    listed at selected_columns. Check `here <http://goo.gl/8AROUD>`_ for more
    information on YQL.

    >>> request_quotes(['AAPL'], ['Name', 'PreviousClose'])
    {
        'PreviousClose': '95.60',
        'Name': 'Apple Inc.'
    }

    :param table: Table name.
    :type table: string
    :param tickers_list: List of tickers that will be returned.
    :type tickers_list: list of strings
    :param selected_columns: List of columns to be returned, defaults to ['*']
    :type selected_columns: list of strings, optional
    :returns: Requested quotes.
    :rtype: json
    :raises: TypeError, TypeError
    """
    __validate_list(tickers_list)
    __validate_list(selected_columns)
    query = 'select {cols} from yahoo.finance.quotes where symbol in ({vals})'
    query = query.format(
        cols=', '.join(selected_columns),
        vals=', '.join('"{0}"'.format(s) for s in tickers_list)
    )

    response = __yahoo_request(query)

    if not response:
        raise RequestError('Unable to process the request. Check if the ' +
                           'columns selected are valid.')

    if not type(response['quote']) is list:
        return [response['quote']]
    return response['quote']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号