本文整理匯總了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