def update_daily():
'''
??????
:return:
'''
# ??????
SaveData.daily_market()
time.sleep(20)
daily_conn = get_mysql_conn('daily')
cursor = daily_conn.cursor()
today = datetime.datetime.now().strftime('%Y-%m-%d')
cmd = 'select * from `{}`;'.format(today)
cursor.execute(cmd)
#today = '2017-11-17'
#daily_df = pd.read_sql_table(today,daily_conn,index_col='index')
days_info = cursor.fetchall()
for i in days_info:
code = i[1]
name = i[2]
close = i[4]
opens = i[5]
high = i[6]
low = i[7]
vol = i[9]
amount = i[11]
try:
history_conn = get_mysql_conn('history')
history_cur = history_conn.cursor()
history_cur.execute('select count(*) from `{}`;'.format(code))
except Exception,e:
print e
continue
l=history_cur.fetchone()
df = pd.DataFrame(columns=['datetime', 'code', 'name', 'open', 'close', 'high', 'low', 'vol', 'amount'])
df.loc[l] = [today, code, name, opens, close, high, low, vol, amount]
try:
df.to_sql(code, engine, if_exists='append')
print code
except Exception, e:
print df
print e
评论列表
文章目录