strSql="SELECT SUM(sell_price-buy_price) FROM view_match_news_stock WHERE TO_DAYS(%s)=TO_DAYS(news_time) AND newsUptrendMan=1 AND buy_price > 0.0 AND sell_price>0.0"%pretime
printstrSql
cur.execute(strSql)
conn.commit()
result=cur.fetchall()
profit=list(result)[0][0]
ifprofitisNone:
profit=0
printprofit
strSql="SELECT COUNT(DISTINCT(news_id)) FROM view_match_news_stock WHERE TO_DAYS(%s)=TO_DAYS(news_time) AND newsUptrendMan=1 AND buy_price > 0.0 AND sell_price>0.0"%pretime
printstrSql
cur.execute(strSql)
conn.commit()
result=cur.fetchall()
numNews=list(result)[0][0]
printnumNews
strSql="SELECT COUNT(DISTINCT(stock_code)) FROM view_match_news_stock WHERE TO_DAYS(%s)=TO_DAYS(news_time) AND newsUptrendMan=1 AND buy_price > 0.0 AND sell_price>0.0"%pretime
printstrSql
cur.execute(strSql)
conn.commit()
result=cur.fetchall()
numStock=list(result)[0][0]
printnumStock
now=time.localtime()
str_time=time.strftime('%Y-%m-%d',now)
sqlCount="SELECT COUNT(*) FROM tbl_stats WHERE DATE_FORMAT(create_datetime, \"%Y-%m-%d\")=DATE_FORMAT(\""+str(str_time)+"\", \"%Y-%m-%d\")"
printsqlCount
#判断是否已存在
cur.execute(sqlCount)
conn.commit()
result=cur.fetchall()
numCount=list(result)[0][0]+0
printnumCount
# print "matchid:" + str(matchid)
# print "sellprice: " + str(sellprice)
# print "stockcode: " + str(stockcode)
strSql=""
ifnumCount==0:
strSql="insert into tbl_stats(profit, num_news, num_stocks, create_datetime) VALUES (%f,%d, %d, '%s')"%(profit,numNews,numStock,str_time)
else:
strSql="update tbl_stats set profit=\""+str(profit)+"\",num_news=\""+str(numNews)+"\",num_stocks=\""+str(numStock)+\
"\" WHERE DATE_FORMAT(create_datetime, \"%Y-%m-%d\")=DATE_FORMAT(\""+str(str_time)+"\", \"%Y-%m-%d\")"
"select * from tbl_match where news_fk_id in (select id from tbl_news where TO_DAYS(news_time)=TO_DAYS(%s) and newsUptrendMan=1) and buy_price is not null"%pretime)
conn.commit()
result=cur.fetchall()
matchlist=list(result)
selldict={}
formatchiteminmatchlist:
stockid1=matchitem[2]
cur.execute("select stock_code from tbl_stock where id=%s"%stockid1)