shared_data.py 文件源码

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

项目:dashing 作者: BCable 项目源码 文件源码
def update_quotes():
    url = "http://finance.yahoo.com/d/quotes.csv?s={}&f=sc1p2oghl1".format(
        "+".join(stocks.keys())
    )

    buf = cStringIO.StringIO()

    curl = pycurl.Curl()
    curl.setopt(pycurl.URL, url)
    curl.setopt(pycurl.WRITEFUNCTION, buf.write)
    curl.setopt(pycurl.FOLLOWLOCATION, 1)
    curl.perform()
    data = buf.getvalue()

    data = data.replace('"', "")
    quote_lines = data.split("\n")

    new_quotes = []

    for line in quote_lines:
        fields = line.split(",")

        if len(fields) == 7:
            new_quotes.append({
                'symbol': fields[0],
                'change': fields[1],
                'pctchange': fields[2],
                'open': fields[3],
                'low': fields[4],
                'high': fields[5],
                'last': fields[6]
            })

    new_quotes.sort(key=lambda x: quotes_order(x))

    if len(quotes) == DATA_POINTS:
        quotes.pop(DATA_POINTS-1)

    quotes.insert(0, new_quotes)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号