|
@@ -15,7 +15,7 @@ field = ['time', 'open', 'close', 'high', 'low', 'volume', 'amount']
|
|
|
cpu_count = mp.cpu_count()
|
|
|
|
|
|
|
|
|
-def to_sql(stock_list, eng_b, eng_f):
|
|
|
+def to_sql(stock_list, eng_back, eng_front):
|
|
|
print(dt.now(), '开始循环入库!')
|
|
|
for stock in stock_list:
|
|
|
print(stock)
|
|
@@ -26,7 +26,7 @@ def to_sql(stock_list, eng_b, eng_f):
|
|
|
df['time'] = df['time'].apply(lambda x: dt.fromtimestamp(x / 1000.0))
|
|
|
df.reset_index(drop=True, inplace=True)
|
|
|
print(df)
|
|
|
- df.to_sql('%s_1d' % stock, con=eng_b, index=True, if_exists='append')
|
|
|
+ df.to_sql('%s_1d' % stock, con=eng_back, index=True, if_exists='append')
|
|
|
|
|
|
for stock in stock_list:
|
|
|
print(stock)
|
|
@@ -37,14 +37,14 @@ def to_sql(stock_list, eng_b, eng_f):
|
|
|
df['time'] = df['time'].apply(lambda x: dt.fromtimestamp(x / 1000.0))
|
|
|
df.reset_index(drop=True, inplace=True)
|
|
|
print(df)
|
|
|
- df.to_sql('%s_1d' % stock, con=eng_f, index=True, if_exists='append')
|
|
|
+ df.to_sql('%s_1d' % stock, con=eng_front, index=True, if_exists='append')
|
|
|
|
|
|
|
|
|
-def download_data(stock_list, eng_b, eng_f):
|
|
|
+def download_data(stock_list, eng_back, eng_front):
|
|
|
print(dt.now(), '开始下载!')
|
|
|
xtdata.download_history_data2(stock_list=stock_list, period='1d', start_time='', end_time='')
|
|
|
print(dt.now(), '下载完成,准备入库!')
|
|
|
- to_sql(stock_list, eng_b, eng_f)
|
|
|
+ to_sql(stock_list, eng_back, eng_front)
|
|
|
|
|
|
|
|
|
# def to_df(key, values, engine):
|
|
@@ -64,7 +64,7 @@ if __name__ == '__main__':
|
|
|
# download_data(stocks, eng_b, eng_f)
|
|
|
|
|
|
scheduler = BlockingScheduler()
|
|
|
- scheduler.add_job(func=download_data, trigger='cron', hour='15', minute='45', args=[stocks, engine],
|
|
|
+ scheduler.add_job(func=download_data, trigger='cron', hour='15', minute='45', args=[stocks, eng_b, eng_f],
|
|
|
timezone="Asia/Shanghai")
|
|
|
try:
|
|
|
scheduler.start()
|