from chpackage.param_info import get_param_info BASE_DIR = os.path.dirname(os.path.abspath(__file__)) CONFIG_INFO_FILE = "%s/%s" % (BASE_DIR, "Config.ini") PARAINFO = get_param_info(CONFIG_INFO_FILE) # 引入mysql操作函数 from chpackage import torndb mysqlExe = torndb.Connection( host = "{0}:{1}".format(PARAINFO["DB_HOST"], PARAINFO["DB_PORT"]), database = PARAINFO["DB_NAME"], user = PARAINFO["USER_NAME"], password = PARAINFO["USER_PWD"], ) pro = ts.pro_api(PARAINFO["TUSHARE_TOKEN"]) tp = Tushare_Proc(pro, mysqlExe) def get_trade_cal(): tradeCalInfo = pro.trade_cal(exchange='', start_date='20190101', end_date='20190103') datas = tradeCalInfo.to_dict("records") return datas if __name__ == '__main__': tradeCalDict = get_trade_cal() for tradeCalInfo in tradeCalDict: if tradeCalInfo["is_open"] == 0: continue
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) CONFIG_INFO_FILE = "%s/%s" % (BASE_DIR, "Config.ini") PARAINFO = get_param_info(CONFIG_INFO_FILE) # 引入mysql操作函数 mysqlExe = torndb.Connection( host="{0}:{1}".format(PARAINFO["DB_HOST"], PARAINFO["DB_PORT"]), database=PARAINFO["DB_NAME"], user=PARAINFO["USER_NAME"], password=PARAINFO["USER_PWD"], ) busiDate = time.strftime('%Y%m%d', time.localtime(time.time())) pro = ts.pro_api(PARAINFO["TUSHARE_TOKEN"]) tp = Tushare_Proc(pro, mysqlExe) def imp_basic_datas_2_db(): ''' 该函数集合执行的是无参数或固定参数的数据导入 ''' tp.proc_main_stock_basic_datas() tp.proc_main_trade_cal_datas("20010101", "20181231") tp.proc_main_stock_company_datas() tp.proc_main_hs_const_datas("SH") tp.proc_main_hs_const_datas("SZ") tp.proc_main_new_share_datas() tp.proc_main_fund_company_datas() tp.proc_main_concept_datas({"inputCode": "ts", "codeType": "src"}) tp.proc_main_fund_basic_datas({"inputCode": "E", "codeType": "market"}) tp.proc_main_fund_basic_datas({"inputCode": "O", "codeType": "market"})
# %% 导入包 import tushare as ts import pandas as pd import matplotlib.pyplot as plt from collections import OrderedDict import os import re import time from multiprocessing import Pool from exec_class import Tushare_Proc import traceback from chpackage.param_info import get_param_info BASE_DIR = os.path.dirname(os.getcwd()) CONFIG_INFO_FILE = "%s/%s" % (BASE_DIR, "Config.ini") PARAINFO = get_param_info(CONFIG_INFO_FILE) # 引入mysql操作函数 from chpackage import torndb mysqlExe = torndb.Connection( host="{0}:{1}".format(PARAINFO["DB_HOST"], PARAINFO["DB_PORT"]), database=PARAINFO["DB_NAME"], user=PARAINFO["USER_NAME"], password=PARAINFO["USER_PWD"], ) pro = ts.pro_api(PARAINFO["TUSHARE_TOKEN"]) # tp = Tushare_Proc(pro, mysqlExe) tp = Tushare_Proc(pro, mysqlExe, busiDate="20190106")