2017-04-09 00:50:14 +08:00
|
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
|
# cp936
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# 作者:fasiondog
|
|
|
|
|
# 历史:1)20100220, Added by fasiondog
|
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
|
usr_dir = os.path.expanduser('~')
|
|
|
|
|
hku_dir = usr_dir + '/.hikyuu'
|
|
|
|
|
|
|
|
|
|
if not os.path.lexists(hku_dir):
|
|
|
|
|
os.mkdir(hku_dir)
|
|
|
|
|
|
2017-05-07 01:27:33 +08:00
|
|
|
|
def ask_question(question, default_anwser='N'):
|
|
|
|
|
flag = False
|
|
|
|
|
x = ''
|
|
|
|
|
while not flag:
|
|
|
|
|
x = input(question)
|
|
|
|
|
if x == '':
|
|
|
|
|
x = default_anwser
|
|
|
|
|
flag = True if (x=='' or x=='Y' or x=='y' or x=='N' or x=='n') else False
|
|
|
|
|
return False if (x=='' or x=='N' or x=='n') else True
|
|
|
|
|
|
2017-04-09 00:50:14 +08:00
|
|
|
|
data_config_file = hku_dir + '/data_dir.ini'
|
|
|
|
|
if os.path.exists(data_config_file):
|
|
|
|
|
os.remove(data_config_file);
|
|
|
|
|
|
2017-07-21 01:13:51 +08:00
|
|
|
|
default_dir = "c:\stock" if sys.platform == "win32" else usr_dir + "/stock"
|
|
|
|
|
data_directory = input("\n请输入股票数据存放路径(默认" + default_dir + "):")
|
2017-04-09 00:50:14 +08:00
|
|
|
|
if data_directory == '':
|
2017-07-21 01:13:51 +08:00
|
|
|
|
data_directory = default_dir
|
|
|
|
|
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(data_config_file, 'w', encoding = 'utf-8') as conf:
|
2017-04-09 00:50:14 +08:00
|
|
|
|
conf.writelines(['[data_dir]\n', 'data_dir=' + data_directory])
|
|
|
|
|
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
|
|
|
|
import_config = """
|
|
|
|
|
;db - 指定基础信息数据库
|
|
|
|
|
;sql - 当指定的基础信息数据库不存在时,使用该指定的脚本创建数据库
|
|
|
|
|
[database]
|
2017-07-18 02:17:20 +08:00
|
|
|
|
db = {dir}/stock.db
|
|
|
|
|
sql = {dir}/createdb.sql
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
|
|
|
|
; ☆☆☆ 注:权息信息目前指支持钱龙数据格式
|
|
|
|
|
;sh、sz分别指定上证、深圳的权息数据所在目录
|
|
|
|
|
[weight]
|
2017-07-12 02:29:57 +08:00
|
|
|
|
sh = {dir}/weight/shase/weight
|
|
|
|
|
sz = {dir}/weight/sznse/weight
|
|
|
|
|
;sh = D:\LON\QLDATA\history\SHASE\weight
|
|
|
|
|
;sz = D:\LON\QLDATA\history\SZNSE\weight
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
|
|
|
|
;指定K线数据源,格式为 “类型, 根目录”(类型仅能为 dzh 或 tdx,即大智慧、通达信)
|
|
|
|
|
;可多个数据源同时导入,防止信息遗漏
|
|
|
|
|
[from]
|
|
|
|
|
1 = tdx, {tdx}
|
|
|
|
|
;2 = dzh, d:\DZH5
|
|
|
|
|
|
|
|
|
|
;指定K线导入的目标文件
|
|
|
|
|
;选项“all”代表不管基础信息库中是否存在该股票,都将其K线导入
|
|
|
|
|
;如果选择all选择为true,将会导入很多不需要的K线数据,一般仅用于备份数据或将来使用
|
|
|
|
|
;all默认为false,如目前数据库仅配置导入A股、B股、基金,而不导入国债
|
|
|
|
|
[dest]
|
|
|
|
|
;all = True
|
2017-07-18 02:17:20 +08:00
|
|
|
|
sh_day = {dir}/sh_day.h5
|
|
|
|
|
sz_day = {dir}/sz_day.h5
|
|
|
|
|
sh_5min = {dir}/sh_5min.h5
|
|
|
|
|
sz_5min = {dir}/sz_5min.h5
|
|
|
|
|
sh_1min = {dir}/sh_1min.h5
|
|
|
|
|
sz_1min = {dir}/sz_1min.h5
|
2017-05-07 01:27:33 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
hikyuu_config = """
|
2017-10-14 03:08:49 +08:00
|
|
|
|
[hikyuu]
|
2017-07-18 02:17:20 +08:00
|
|
|
|
tmpdir = {dir}/tmp
|
2017-10-14 03:08:49 +08:00
|
|
|
|
logger = {dir}/logger.properties
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
|
|
|
|
[block]
|
|
|
|
|
type = qianlong
|
2017-07-18 02:17:20 +08:00
|
|
|
|
dir = {dir}/block
|
2017-05-07 01:27:33 +08:00
|
|
|
|
指数板块 = zsbk.ini
|
|
|
|
|
行业板块 = hybk.ini
|
|
|
|
|
地域板块 = dybk.ini
|
|
|
|
|
概念板块 = gnbk.ini
|
|
|
|
|
self = self.ini
|
|
|
|
|
|
|
|
|
|
[preload]
|
|
|
|
|
day = 1
|
|
|
|
|
week = 0
|
|
|
|
|
month = 0
|
|
|
|
|
quarter = 0
|
|
|
|
|
halfyear = 0
|
|
|
|
|
year = 0
|
|
|
|
|
|
|
|
|
|
[baseinfo]
|
|
|
|
|
type = sqlite3
|
2017-07-18 02:17:20 +08:00
|
|
|
|
db = {dir}/stock.db
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
2017-10-14 03:08:49 +08:00
|
|
|
|
[kdata]
|
2017-05-07 01:27:33 +08:00
|
|
|
|
;type = tdx
|
2017-10-14 03:08:49 +08:00
|
|
|
|
;dir = D:\\TdxW_HuaTai\\vipdoc
|
2017-05-07 01:27:33 +08:00
|
|
|
|
type = hdf5
|
2017-10-14 03:08:49 +08:00
|
|
|
|
sh_day = {dir}/sh_day.h5
|
|
|
|
|
sh_min = {dir}/sh_1min.h5
|
|
|
|
|
sh_min5 = {dir}/sh_5min.h5
|
|
|
|
|
sz_day = {dir}/sz_day.h5
|
|
|
|
|
sz_min = {dir}/sz_1min.h5
|
|
|
|
|
sz_min5 = {dir}/sz_5min.h5
|
2017-05-07 01:27:33 +08:00
|
|
|
|
"""
|
|
|
|
|
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_default_dir = "c:\TdxW_HuaTai" if sys.platform == "win32" else usr_dir + "/.wine/driver/c/Tdx_HuaTai"
|
|
|
|
|
tdx_input_str = "请输入通达信安装路径(默认从" + tdx_default_dir + "):"
|
2017-04-09 00:50:14 +08:00
|
|
|
|
|
|
|
|
|
if not os.path.lexists(data_directory):
|
|
|
|
|
shutil.copytree('config', data_directory)
|
|
|
|
|
os.remove(data_directory + '/__init__.py')
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
2017-04-09 00:50:14 +08:00
|
|
|
|
if sys.platform == 'win32':
|
2017-05-07 01:27:33 +08:00
|
|
|
|
filename = data_directory + '/hikyuu_win.ini'
|
2017-04-09 00:50:14 +08:00
|
|
|
|
else:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
filename = data_directory + '/hikyuu_linux.ini'
|
|
|
|
|
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(filename, 'w', encoding = 'utf-8') as f:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
f.write(hikyuu_config.format(dir=data_directory))
|
|
|
|
|
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_dir = input(tdx_input_str)
|
2017-05-07 01:27:33 +08:00
|
|
|
|
if tdx_dir == '':
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_dir = tdx_default_dir
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(data_directory + '/importdata.ini', 'w', encoding = 'utf-8') as f:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
f.write(import_config.format(dir=data_directory, tdx=tdx_dir))
|
|
|
|
|
|
|
|
|
|
os.mkdir(data_directory + '/tmp')
|
2017-07-12 02:29:57 +08:00
|
|
|
|
|
|
|
|
|
|
2017-04-09 00:50:14 +08:00
|
|
|
|
else:
|
|
|
|
|
if os.path.lexists(data_directory + '/block'):
|
2017-05-07 01:27:33 +08:00
|
|
|
|
pass
|
2017-05-31 02:02:40 +08:00
|
|
|
|
x = ask_question("block目录已存在是否覆盖?(Y/[N]):")
|
|
|
|
|
if x:
|
|
|
|
|
shutil.rmtree(data_directory + '/block')
|
|
|
|
|
shutil.copytree('config/block', data_directory + '/block')
|
|
|
|
|
os.remove(data_directory + '/block/__init__.py')
|
2017-07-12 02:29:57 +08:00
|
|
|
|
else:
|
|
|
|
|
shutil.copytree('config/block', data_directory + '/block')
|
|
|
|
|
os.remove(data_directory + '/block/__init__.py')
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
2017-04-09 00:50:14 +08:00
|
|
|
|
if os.path.exists(data_directory + '/logger.properties'):
|
2017-05-07 01:27:33 +08:00
|
|
|
|
pass
|
2017-05-31 02:02:40 +08:00
|
|
|
|
x = ask_question("logger.properties文件已存在是否覆盖?(Y/[N]):")
|
|
|
|
|
if x:
|
|
|
|
|
os.remove(data_directory + '/logger.properties')
|
|
|
|
|
shutil.copy('config/logger.properties', data_directory + '/logger.properties')
|
2017-07-12 02:29:57 +08:00
|
|
|
|
else:
|
|
|
|
|
shutil.copy('config/logger.properties', data_directory + '/logger.properties')
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
2017-04-09 00:50:14 +08:00
|
|
|
|
if os.path.exists(data_directory + '/importdata.ini'):
|
|
|
|
|
x = ask_question("importdata.ini文件已存在是否覆盖?(Y/[N]):")
|
|
|
|
|
if x:
|
|
|
|
|
os.remove(data_directory + '/importdata.ini')
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_dir = input(tdx_input_str)
|
2017-05-07 01:27:33 +08:00
|
|
|
|
if tdx_dir == '':
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_dir = tdx_default_dir
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(data_directory + '/importdata.ini', 'w', encoding = 'utf-8') as f:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
f.write(import_config.format(dir=data_directory, tdx=tdx_dir))
|
2017-05-31 02:02:40 +08:00
|
|
|
|
else:
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_dir = input(tdx_input_str)
|
2017-05-31 02:02:40 +08:00
|
|
|
|
if tdx_dir == '':
|
2017-07-21 01:13:51 +08:00
|
|
|
|
tdx_dir = tdx_default_dir
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(data_directory + '/importdata.ini', 'w', encoding = 'utf-8') as f:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
f.write(import_config.format(dir=data_directory, tdx=tdx_dir))
|
|
|
|
|
|
2017-04-09 00:50:14 +08:00
|
|
|
|
if os.path.exists(data_directory + '/createdb.sql'):
|
2017-05-07 01:27:33 +08:00
|
|
|
|
os.remove(data_directory + '/createdb.sql')
|
2017-07-12 02:29:57 +08:00
|
|
|
|
shutil.copy('config/createdb.sql', data_directory + '/createdb.sql')
|
2017-04-09 00:50:14 +08:00
|
|
|
|
|
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
|
hikyuu_ini = '/hikyuu_win.ini'
|
|
|
|
|
else:
|
|
|
|
|
hikyuu_ini = '/hikyuu_linux.ini'
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
|
|
|
|
filename = data_directory + hikyuu_ini
|
2017-04-09 00:50:14 +08:00
|
|
|
|
|
|
|
|
|
if os.path.exists(data_directory + hikyuu_ini):
|
|
|
|
|
x = ask_question(hikyuu_ini[1:] + "文件已存在是否覆盖?(Y/[N]):")
|
|
|
|
|
if x:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
os.remove(filename)
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(data_directory + hikyuu_ini, 'w', encoding = 'utf-8') as f:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
f.write(hikyuu_config.format(dir=data_directory))
|
|
|
|
|
else:
|
2017-10-31 15:00:23 +08:00
|
|
|
|
with open(data_directory + hikyuu_ini, 'w', encoding = 'utf-8') as f:
|
2017-05-07 01:27:33 +08:00
|
|
|
|
f.write(hikyuu_config.format(dir=data_directory))
|
2017-07-12 02:29:57 +08:00
|
|
|
|
|
|
|
|
|
if not os.path.lexists(data_directory + '/tmp'):
|
|
|
|
|
os.mkdir(data_directory + '/tmp')
|
2017-05-07 01:27:33 +08:00
|
|
|
|
|
|
|
|
|
#print(import_config.format(dir=data_directory))
|