本文整理汇总了Python中models.Stock.query方法的典型用法代码示例。如果您正苦于以下问题:Python Stock.query方法的具体用法?Python Stock.query怎么用?Python Stock.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Stock
的用法示例。
在下文中一共展示了Stock.query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_stocks
# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import query [as 别名]
def _update_stocks(symbols):
"""
Update models.Stock entities.
:param symbols: Iterable of stock symbols to update.
:return: dict mapping symbols to new prices, dict mapping symbols to (old price, new price) for changed symbols.
"""
to_put = []
symbol_price_updated_dict = {}
if symbols is None:
stocks_ = list(Stock.query())
symbols = [s.key.id() for s in stocks_]
else:
stocks_ = [Stock.get_by_id(s) for s in symbols]
symbol_price_dict = stocks.get_stock_prices(symbols)
for stock in stocks_:
if stock is None:
continue
symbol = stock.key.id()
price = symbol_price_dict.get(symbol, None)
if stock.price != price:
symbol_price_updated_dict[symbol] = (stock.price, price)
stock.price = price
to_put.append(stock)
ndb.put_multi(to_put)
return symbol_price_dict, symbol_price_updated_dict