本文整理汇总了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()