本文整理匯總了Python中models.Stock.put方法的典型用法代碼示例。如果您正苦於以下問題:Python Stock.put方法的具體用法?Python Stock.put怎麽用?Python Stock.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Stock
的用法示例。
在下文中一共展示了Stock.put方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_market
# 需要導入模塊: from models import Stock [as 別名]
# 或者: from models.Stock import put [as 別名]
def get_market():
#util.clean_market(0)
url = 'http://pregao-online.bmfbovespa.com.br/Cotacoes.aspx'
soup = BeautifulSoup(urlfetch.fetch(url, deadline=50).content, 'lxml')
rate = util.get_exchange()
#dt = get_datetime()
dt = datetime.datetime.now(tz.tzstr('EBST3EBDT'))
market = Market(ref=0, date=dt.date(), time=dt.time(), exchange_rate=rate)
market.put()
table = soup('table', attrs={'id': 'ctl00_DefaultContent_GrdCarteiraIndice'})[0]
for tr in table('tr')[1:]:
tds = tr('td')
code = str(tds[0].string)
name = util.clean_string(tds[1].string)
value = util.get_float(tds[2].string)
diff = util.get_float(tds[3].text.strip())
stock = Stock(name=util.get_or_create_name(0, code, name),
value=value, diff=diff, market=market.key())
stock.put()
示例2: get_market
# 需要導入模塊: from models import Stock [as 別名]
# 或者: from models.Stock import put [as 別名]
def get_market():
#util.clean_market(1)
#dt = get_datetime()
dt = datetime.datetime.now(tz.tzstr('EST5EDT'))
market = Market(ref=1, date=dt.date(), time=dt.time())
market.put()
url = 'http://www.barchart.com/stocks/nasdaq100.php?view=main'
soup = BeautifulSoup(urlfetch.fetch(url, deadline=30).content, 'lxml')
table = soup('table', attrs={'id': 'dt1'})[0]
for tr in table('tr')[1:]:
tds = tr('td')
code = str(tds[0].text)
name = str(tds[1].text)
value = float(tds[2].text.replace(',', ''))
text_replace = tds[4].text.replace(',', '').replace('%', '')
diff = float(text_replace) if text_replace != 'unch' else 0.0
stock = Stock(name=util.get_or_create_name(1, code, name),
value=value, diff=diff, market=market.key())
stock.put()