优化板块数据下载

This commit is contained in:
fasiondog 2024-09-04 05:29:35 +08:00
parent 2f92c91a16
commit 462c243daa
2 changed files with 87 additions and 58 deletions

View File

@ -4,6 +4,7 @@
# Create on: 20240102
# Author: fasiondog
from concurrent.futures import ThreadPoolExecutor
from hikyuu.data.common import MARKET, get_stk_code_name_list
from hikyuu.util import *
from hikyuu.fetcher.stock.zh_block_em import *
@ -12,34 +13,47 @@ from hikyuu.fetcher.stock.zh_block_em import *
def em_import_block_to_mysql(connect, code_market_dict, categorys=('行业板块', '概念板块', '地域板块', '指数板块')):
all_block_info = {}
with ThreadPoolExecutor(4) as executor:
if '行业板块' in categorys:
t1 = executor.submit(get_all_hybk_info, code_market_dict)
if '概念板块' in categorys:
t2 = executor.submit(get_all_gnbk_info, code_market_dict)
if '地域板块' in categorys:
t3 = executor.submit(get_all_dybk_info, code_market_dict)
if '指数板块' in categorys:
t4 = executor.submit(get_all_zsbk_info, code_market_dict)
success_fetch_hy = False
if '行业板块' in categorys:
hku_info("获取行业板块信息")
x = get_all_hybk_info(code_market_dict)
x = t1.result()
hku_info("获取行业板块信息完毕")
if x:
all_block_info["行业板块"] = x
success_fetch_hy = True
success_fetch_gn = False
if '概念板块' in categorys:
hku_info("获取概念板块信息")
x = get_all_gnbk_info(code_market_dict)
x = t2.result()
hku_info("获取概念板块信息完毕")
if x:
all_block_info["概念板块"] = x
success_fetch_gn = True
success_fetch_dy = False
if '地域板块' in categorys:
hku_info("获取地域板块信息")
x = get_all_dybk_info(code_market_dict)
x = t3.result()
hku_info("获取地域板块信息完毕")
if x:
all_block_info["地域板块"] = x
success_fetch_dy = True
success_fetch_zs = False
if '指数板块' in categorys:
hku_info("获取指数板块信息")
x = get_all_zsbk_info(code_market_dict)
x = t4.result()
hku_info("获取指数板块信息完毕")
if x:
all_block_info["指数板块"] = x
success_fetch_zs = True

View File

@ -4,42 +4,57 @@
# Create on: 20240102
# Author: fasiondog
from concurrent.futures import ThreadPoolExecutor
from hikyuu.data.common import MARKET, get_stk_code_name_list
from hikyuu.util import *
from hikyuu.fetcher.stock.zh_block_em import *
@spend_time
def em_import_block_to_sqlite(connect, code_market_dict, categorys=('行业板块', '概念板块', '地域板块', '指数板块')):
all_block_info = {}
with ThreadPoolExecutor(4) as executor:
if '行业板块' in categorys:
t1 = executor.submit(get_all_hybk_info, code_market_dict)
if '概念板块' in categorys:
t2 = executor.submit(get_all_gnbk_info, code_market_dict)
if '地域板块' in categorys:
t3 = executor.submit(get_all_dybk_info, code_market_dict)
if '指数板块' in categorys:
t4 = executor.submit(get_all_zsbk_info, code_market_dict)
success_fetch_hy = False
if '行业板块' in categorys:
hku_info("获取行业板块信息")
x = get_all_hybk_info(code_market_dict)
x = t1.result()
hku_info("获取行业板块信息完毕")
if x:
all_block_info["行业板块"] = x
success_fetch_hy = True
success_fetch_gn = False
if '概念板块' in categorys:
hku_info("获取概念板块信息")
x = get_all_gnbk_info(code_market_dict)
x = t2.result()
hku_info("获取概念板块信息完毕")
if x:
all_block_info["概念板块"] = x
success_fetch_gn = True
success_fetch_dy = False
if '地域板块' in categorys:
hku_info("获取地域板块信息")
x = get_all_dybk_info(code_market_dict)
x = t3.result()
hku_info("获取地域板块信息完毕")
if x:
all_block_info["地域板块"] = x
success_fetch_dy = True
success_fetch_zs = False
if '指数板块' in categorys:
hku_info("获取指数板块信息")
x = get_all_zsbk_info(code_market_dict)
x = t4.result()
hku_info("获取指数板块信息完毕")
if x:
all_block_info["指数板块"] = x
success_fetch_zs = True
@ -85,8 +100,8 @@ if __name__ == "__main__":
import sqlite3
from hikyuu.data.common_sqlite3 import create_database
dest_dir = "/home/fasiondog/stock"
# dest_dir = "d:\\stock"
# dest_dir = "/home/fasiondog/stock"
dest_dir = "d:\\stock"
connect = sqlite3.connect(dest_dir + "/stock.db")
create_database(connect)