def classification(class_types):
    if class_types == 'industry':
        industry_classified = ts.get_industry_classified()
        industry_classified.to_csv('D:\\ts\\classification\\industry_classified.csv', encoding='gbk')
    elif class_types == 'concept':
        concept_classified = ts.get_concept_classified()
        concept_classified.to_csv('D:\\ts\\classification\\concept_classified.csv', encoding='gbk')
    elif class_types == 'area':
        area_classified = ts.get_area_classified()
        area_classified.to_csv('D:\\ts\\classification\\area_classified.csv', encoding='gbk')
    elif class_types == 'sme':
        sme_classified = ts.get_sme_classified()
        sme_classified.to_csv('D:\\ts\\classification\\sme_classified.csv', encoding='gbk')
    elif class_types == 'gem':
        gem_classified = ts.get_gem_classified()
        gem_classified.to_csv('D:\\ts\\classification\\gem_classified.csv', encoding='gbk')
    elif class_types == 'st':
        st_classified = ts.get_st_classified()
        st_classified.to_csv('D:\\ts\\classification\\st_classified.csv', encoding='gbk')
    elif class_types == 'hs300':
        hs300s = ts.get_hs300s()
        hs300s.to_csv('D:\\ts\\classification\\hs300s.csv', encoding='gbk')
    elif class_types == 'sz50':
        sz50s = ts.get_sz50s()
        sz50s.to_csv('D:\\ts\\classification\\sz50s.csv', encoding='gbk')
    elif class_types == 'zz500':
        zz500s = ts.get_zz500s()
        zz500s.to_csv('D:\\ts\\classification\\zz500s.csv', encoding='gbk')
    elif class_types == 'terminated':
        terminated = ts.get_terminated()
        terminated.to_csv('D:\\ts\\classification\\terminated.csv', encoding='gbk')
    elif class_types == 'suspended':
        suspended = ts.get_suspended()
        suspended.to_csv('D:\\ts\\classification\\suspended.csv', encoding='gbk')
 def get_ST(self):
     # 暂停上市
     zt = ts.get_suspended()
     print zt
     # 终止上市
     zz = ts.get_terminated()
     print zz
Exemple #3
0
 def get_ST(self):
     # 暂停上市
     zt = ts.get_suspended()
     print zt
     # 终止上市
     zz = ts.get_terminated()
     print zz
Exemple #4
0
def get_suspended():
    try:
        logger.info('get suspended data starting...')
        df = ts.get_suspended()
        logger.info('get suspended data end...')
    except:
        logger.exception('some errors between get suspended data end...')
    return df
Exemple #5
0
def get_suspended_info():
    # 被暂停上市的股票列表
    df = ts.get_suspended()
    df
    if df is not None:
        res = df.to_sql(all_suspended_table, engine, if_exists='replace')
        msg = 'ok' if res is None else res
        print('获取被暂停上市的股票列表: ' + msg + '\n')
    else:
        print('获取被暂停上市的股票列表: ' + 'None' + '\n')
def getSuspended():
    '''
    获取被暂停上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。
    返回值说明:
    code:股票代码
    name:股票名称
    oDate:上市日期
    tDate:暂停上市日期
    '''
    return ts.get_suspended()
Exemple #7
0
 def get_suspended_classified(self):
     """
    'suspended',##暂停上市股票列表
     """
     suspended = ts.get_suspended()
     suspended['suspendedName'] = 1
     suspended = suspended[['code','suspendedName','oDate','tDate']]
     
     suspended.columns = ['code','suspendedName','suspendedODate','suspendedTDate']
     self.data = pd.merge(self.data,suspended,on=['code'],how='outer')  
Exemple #8
0
def getstockclassifieddata():
    mylogger = getmylogger()
    print("start")
    scdict = {
        'industry': '行业分类',
        'concept': '概念分类',
        'area': '地域分类',
        'sme': '中小板分类',
        'gem': '创业板分类',
        'st': '风险警示板分类',
        'hs300s': '沪深300成份及权重',
        'sz50s': '上证50成份股',
        'zz500s': '中证500成份股',
        'terminated': '终止上市股票列表',
        'suspended': '暂停上市股票列表'
    }

    for sc in scdict:
        sctbname = sc
        scinfo = scdict[sctbname]
        try:
            if sc == "industry":
                df = ts.get_industry_classified()
            elif sc == "concept":
                df = ts.get_concept_classified()
            elif sc == "area":
                df = ts.get_area_classified()
            elif sc == "sme":
                df = ts.get_sme_classified()
            elif sc == "gem":
                df = ts.get_gem_classified()
            elif sc == "st":
                df = ts.get_st_classified()
            elif sc == "hs300s":
                df = ts.get_hs300s()
            elif sc == "zz500s":
                df = ts.get_zz500s()
            elif sc == "sz50s":
                df = ts.get_sz50s()
            elif sc == "terminated":
                df = ts.get_terminated()
            elif sc == "suspended":
                df = ts.get_suspended()
            else:
                mylogger.info("没有执行命令。")
            if df is not None:
                tosql(df, sctbname, "replace", scinfo, mylogger)
            else:
                mylogger.info("没有%s数据。" % scinfo)
        except Exception:
            tracelog = traceback.format_exc()
            mylogger.info("获取数据异常。")
            mylogger.info(tracelog)
def load_data():
    #下载公司基本信息,包括股票代码、pe、市盈率等数据
    try:
        rs = ts.get_suspended()
        pd.DataFrame.to_sql(rs,
                            table_name,
                            con=conn,
                            flavor='mysql',
                            if_exists='replace',
                            index=True)
    except Exception as e:
        print(e.message)
        print("公司基本分类信息数据出错")
def load_data():
    #下载公司基本信息,包括股票代码、pe、市盈率等数据
    try:
        rs = ts.get_suspended()
        pd.DataFrame.to_sql(rs,
                            name=table_name,
                            con=con,
                            schema=db,
                            if_exists='replace',
                            index=True)
    except Exception as e:
        print(e)
        print("公司基本分类信息数据出错")
Exemple #11
0
def get_industry():
    #data = ts.get_industry_classified()   #行业分类
    #data = ts.get_concept_classified()        #概念分类
    #data = ts.get_area_classified()        #地域分类
    #data = ts.get_sme_classified()        #获取中小板股票数据,即查找所有002开头的股票
    #data = ts.get_gem_classified()        #获取创业板股票数据,即查找所有300开头的股票
    #data = ts.get_st_classified()        #获取风险警示板股票数据,即查找所有st股票
    #data = ts.get_hs300s()        #获取沪深300当前成份股及所占权重
    #data = ts.get_sz50s()        #获取上证50成份股
    #data = ts.get_zz500s()        #获取中证500成份股
    #data = ts.get_terminated()        #获取已经被终止上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。
    data = ts.get_suspended()        #获取被暂停上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。
    print(data)
Exemple #12
0
def get_quit(f):
    # 获取终止上市的股票列表
    if f.get(conf.HDF5_BASIC_QUIT_TERMINATE) is not None:
        del f[conf.HDF5_BASIC_QUIT_TERMINATE]
    df = ts.get_terminated()
    df = df.drop("name", axis=1)
    tool.create_df_dataset(f, conf.HDF5_BASIC_QUIT_TERMINATE, df)

    # 获取暂定上市的股票列表
    if f.get(conf.HDF5_BASIC_QUIT_SUSPEND) is not None:
        del f[conf.HDF5_BASIC_QUIT_SUSPEND]
    df = ts.get_suspended()
    df = df.drop("name", axis=1)
    tool.create_df_dataset(f, conf.HDF5_BASIC_QUIT_SUSPEND, df)
    return
Exemple #13
0
def update_suspend(request):
    '''更新暂停上市'''
    stock_suspend.objects.all().delete()

    rltobj = ts.get_suspended()
    objlist = []
    for i in range(len(rltobj)):
        tmpobj = stock_suspend(code=rltobj.loc[i]['code'],
                               name=rltobj.loc[i]['name'],
                               s_date=rltobj.loc[i]['oDate'],
                               e_date=rltobj.loc[i]['tDate'])
        objlist.append(tmpobj)

    stock_suspend.objects.bulk_create(objlist)

    return HttpResponse('succ.{0}条!'.format(len(objlist)))
 def init(self, status):
     #get new delisted data info
     df_terminated = ts.get_terminated()
     if df_terminated is None:return False
     if not df_terminated.empty:
         df = df_terminated
     df_suspended = ts.get_suspended()
     if df_suspended is None:return False
     if not df_suspended.empty:
         df = df.append(df_suspended)
     if not df.empty:
         df = df.reset_index(drop = True)
     #get old delisted data info
     old_df_all = self.get()
     if not old_df_all.empty:
         df = df_delta(df, old_df_all, ['code'])
     if df.empty: return True
     res = self.mysql_client.set(df, self.table)
     if not res: return False
     if status: return self.redis.set(ct.DELISTED_INFO, _pickle.dumps(df, 2))
def save_suspend():
    """获取被暂停上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。"""
    logger.info('Begin get and save suspend clssified.')
    try:
        data_df = ts.get_suspended()
        if data_df is not None and not data_df.empty:
            data = data_df.values
            data_dicts = [{
                'code': row[0],
                'name': row[1],
                'o_date': row[2],
                't_date': row[3],
                'insert_date': today_line
            } for row in data]
            Suspend.insert_many(data_dicts).execute()
            logger.info('Success get and save suspend classified.')
        else:
            logger.warn('Empty get and save suspend classified.')
    except Exception as e:
        logger.exception('Error get and save suspend classified.')
Exemple #16
0
def get_suspended():
    '''
    函数功能:
    --------
    获取所有被暂停上市的股票列表,数据从上交所获取,目前只在上交所有被暂停上市的股票。

    输入参数:
    --------
    无

    输出参数:
    --------
    DataFrame
        code,代码
        name,名称
        oDate,上市日期
        tDate,暂停上市日期
    '''
    # Download data
    suspended = ts.get_suspended()

    # Return Dataframe
    return suspended
Exemple #17
0
from sqlalchemy import create_engine
import tushare as ts

stock_basics = ts.get_stock_basics()  #所有股票列表    stock_basic
industry = ts.get_industry_classified()  # 行业分类                industry
concept = ts.get_concept_classified()  # 概念分类                concept
area = ts.get_area_classified()  # 地域分类                 area
sme = ts.get_sme_classified()  # 中小板                sme
gem = ts.get_gem_classified()  # 创业板                    gem
st = ts.get_st_classified()  # ST风险警示板            st
hs300s = ts.get_hs300s()  # 沪深300               hs300s
sz50s = ts.get_sz50s()  # 上证50                        sz50s
zz500s = ts.get_zz500s()  # 中证500                zz500s
terminated = ts.get_terminated()  # 终止上市    terminated
suspended = ts.get_suspended()  # 暂停上市    suspended

engine = create_engine(
    'mysql://*****:*****@10.20.116.107/CN_BASSOON?charset=utf8')
sme.to_sql('sme', engine, if_exists='append')
gem.to_sql('gem', engine, if_exists='append')
st.to_sql('st', engine, if_exists='append')
hs300s.to_sql('hs300s', engine, if_exists='append')
sz50s.to_sql('sz50s', engine, if_exists='append')
zz500s.to_sql('zz500s', engine, if_exists='append')
terminated.to_sql('terminated', engine, if_exists='append')
suspended.to_sql('suspended', engine, if_exists='append')
stock_basics.to_sql('stock_basics', engine, if_exists='append')
industry.to_sql('industry', engine, if_exists='append')
concept.to_sql('concept', engine, if_exists='append')
area.to_sql('area', engine, if_exists='append')
Exemple #18
0
# name:股票名称
df = ts.get_sz50s()
df.to_sql('t_sz50s', engine)

#409
# 中证500成份股
# 返回值说明
# code:股票代码
# name:股票名称
df = ts.get_zz500s()
df.to_sql('t_zz500s', engine)

# 410
# 终止上市股票列表
# 返回值说明
# code:股票代码
# name:股票名称
# oDate:上市日期
# tDate:终止上市日期
df = ts.get_terminated()
df.to_sql('t_terminated', engine)

# 411
# 暂停上市股票列表
# 返回值说明
# code:股票代码
# name:股票名称
# oDate:上市日期
# tDate:终止上市日期
df = ts.get_suspended()
df.to_sql('t_suspended', engine)
Exemple #19
0
 def get_suspended(self, conns):
     self.base = Base()
     self.financial_data = conns['financial_data']
     self.df = ts.get_suspended()
     self.base.batchwri(self.df, 'suspended', self.financial_data)
Exemple #20
0
 def setSuspendedClassified(self, isSave=False, tableName=CLASSIFIED_SUSPENDED):
     df = ts.get_suspended()
     if isSave is True:
         df.to_sql(tableName, self.engine_sql, if_exists='append')
     return df
Exemple #21
0
def get_suspended_info(file_path):
    suspended_info = ts.get_suspended()
    suspended_info.to_csv(file_path, encoding='utf-8')
    print '\ndownload suspended info finished\n'
Exemple #22
0
def load_company_industry_info(): 
    #下载加载行业分类数据
    try:
        rs=ts.get_industry_classified()
        sql.write_frame(rs, "company_industry_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载公司行业分类信息ok")
    except:
        print("下载公司行业分类信息出错")
    #下载加载概念分类数据
    try:
        rs=ts.get_concept_classified()
        sql.write_frame(rs, "company_concept_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("载公司概念分类信息ok")
    except:
        print("下载公司概念分类信息出错")
    #下载加载地域分类数据
    try:
        rs=ts.get_area_classified()
        sql.write_frame(rs, "company_area_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载公司区域分类信息ok")
    except:
        print("下载公司区域分类信息出错")
    #下载加载中小板分类数据
    try:
        rs=ts.get_sme_classified()
        sql.write_frame(rs, "company_sme_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载中小板分类数据ok")
    except:
        print("下载中小板分类数据出错")
    #下载加载创业板分类数据
    try:
        rs=ts.get_gem_classified()
        sql.write_frame(rs, "company_gem_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载创业板分类数据ok")
    except:
        print("下载创业板分类数据出错")
    #下载加载st板分类数据
    try:
        rs=ts.get_st_classified()
        sql.write_frame(rs, "company_st_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载st板分类数据ok")
    except:
        print("下载st板分类数据出错")
    #下载加载沪深300板分类数据
    try:
        rs=ts.get_hs300s()
        sql.write_frame(rs, "company_hs300_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载加载沪深300板分类数据ok")
    except:
        print("下载加载沪深300板分类数据出错")
    #下载加载上证50板分类数据
    try:
        rs=ts.get_sz50s()
        sql.write_frame(rs, "company_sz50_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载加载上证50板分类数据ok")
    except:
        print("下载加载上证50板分类数据出错")
    #下载加载中证500板分类数据
    try:
        rs=ts.get_zz500s()
        sql.write_frame(rs, "company_zz500_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载加载中证500板分类数据ok")
    except:
        print("下载加载中证500板分类数据出错")
    #下载加载终止上市分类数据
    try:
        rs=ts.get_terminated()
        sql.write_frame(rs, "company_terminated_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载加载终止上市分类数据ok")
    except:
        print("下载加载终止上市分类数据出错")
    #下载加载暂停上市分类数据
    try:
        rs=ts.get_suspended()
        sql.write_frame(rs, "company_suspended_classified", con=conn_company_classified , flavor='mysql', if_exists='replace',index=True)
        print("下载加载暂停上市分类数据ok")
    except:
        print("下载加载暂停上市分类数据出错")
Exemple #23
0
返回值说明:

code:股票代码
name:股票名称'''

print('中证500成份股')
print(ts.get_zz500s())

'''获取已经被终止上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。

返回值说明:

code:股票代码
name:股票名称
oDate:上市日期
tDate:终止上市日期'''
print('终止上市股票列表')
print(ts.get_terminated())

''''获取被暂停上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。

返回值说明:

code:股票代码
name:股票名称
oDate:上市日期
tDate:暂停上市日期'''
print('暂停上市的股票列表')
print(ts.get_suspended())
Exemple #24
0
 def init_suspended_class(self):
     df = ts.get_suspended()
     df.to_csv(self.suspended_class_file)
def classified():

    #在现实交易中,经常会按行业统计股票的涨跌幅或资金进出,本接口按照sina财经对沪深股票进行的行业分类,返回所有股票所属行业的信息。
    #注意:有的股票属于两个行业:如000587
    industry = ts.get_industry_classified()
    industry = industry.drop_duplicates()
    industry_new = data_pro(industry)
    industry_new.rename(columns={'c_name': 'industry'}, inplace=True)

    #返回股票概念的分类数据,现实的二级市场交易中,经常会以”概念”来炒作,在数据分析过程中,可根据概念分类监测资金等信息的变动情况。
    concept = ts.get_concept_classified()
    concept = concept.drop_duplicates()
    concept_new = data_pro(concept)
    concept_new.rename(columns={'c_name': 'concept'}, inplace=True)

    #按地域对股票进行分类,即查找出哪些股票属于哪个省份。
    area = ts.get_area_classified()
    area = area.drop_duplicates()
    area_new = data_pro(area)

    #获取中小板股票数据,即查找所有002开头的股票
    sme = ts.get_sme_classified()
    sme['belong_bk'] = '中小板'
    #获取创业板股票数据,即查找所有300开头的股票
    gem = ts.get_gem_classified()
    gem['belong_bk'] = '创业板'
    #获取风险警示板股票数据,即查找所有st股票
    st = ts.get_st_classified()
    st['belong_bk'] = '风险警示板'
    bk = pd.concat([sme, gem, st], join='outer', axis=0)
    bk = bk.drop_duplicates()
    bk = data_pro(bk)

    # 获取沪深300当前成份股及所占权重
    hs300s = ts.get_hs300s()
    hs300s = hs300s.iloc[:, 1:-1]
    hs300s['belong_cfg'] = '沪深300成份股'
    # 获取上证50成份股
    sz50s = ts.get_sz50s()
    sz50s = sz50s.iloc[:, 1:]
    sz50s['belong_cfg'] = '上证50成份股'
    # 获取中证500成份股
    zz500s = ts.get_zz500s()
    zz500s = zz500s.iloc[:, 1:-1]
    zz500s['belong_cfg'] = '中证500成份股'
    cfg = pd.concat([hs300s, sz50s, zz500s], join='outer', axis=0)
    cfg = cfg.drop_duplicates()
    cfg = data_pro(cfg)

    # 获取已经被终止上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。
    terminated = ts.get_terminated()
    if terminated != None:
        terminated['终止上市'] = '终止上市'

    # 获取被暂停上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。
    suspended = ts.get_suspended()
    if suspended != None:
        suspended['暂停上市'] = '暂停上市'

    # 数据拼接
    table_list = [industry_new, concept_new, area_new, bk, cfg]
    for i in range(len(table_list)):
        if i == 0:
            classified_data = table_list[i]
        else:
            classified_data = pd.merge(classified_data,
                                       table_list[i],
                                       how='outer',
                                       on=['code', 'name'])
    classified_data = classified_data.fillna('未知')

    #一个代码对应多个名称的数据整理
    classified_temp = classified_data.groupby(['code'])
    classified_new = classified_temp.agg(lambda x: '|'.join(x))
    classified_dict = {
        'industry': '所属行业',
        'name': '名称',
        'concept': '概念',
        'area': '区域',
        'belong_bk': '所属板块',
        'belong_cfg': '所属成分股'
    }
    classified_new.columns = classified_new.columns.map(classified_dict)

    industry_list = classified_new['所属行业']
    industry_list = [i.split('|')[0] for i in industry_list]

    classified_new['所属行业'] = industry_list
    return classified_new
Exemple #26
0
print("#0", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23')
print("#1", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23', ktype='W')
print("#2", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23', ktype='M')
print("#3", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23', ktype='5')
print("#4", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23', ktype='15')
print("#5", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23', ktype='30')
print("#6", df)
df = ts.get_hist_data('600848',start='2016-08-05',end='2016-08-23', ktype='60')
print("#7", df)

df = ts.get_index()
printD("ts.get_index", df)

df = ts.get_suspended()
printD("ts.get_suspended()", df)

df = ts.get_sz50s()
printD("ts.get_sz50s", df)

df = ts.get_terminated()
printD("ts.get_terminated", df)

df = ts.get_zz500s()
printD("ts.get_zz500s", df)
Exemple #27
0
    code:股票代码
    name:股票名称

'''
ts.get_zz500s()

# 终止上市股票列表
'''
获取已经被终止上市的股票列表,数据从上交所获取,目前只有在上海证券交易所交易被终止的股票。

返回值说明:

    code:股票代码
    name:股票名称
    oDate:上市日期
    tDate:终止上市日期

'''
ts.get_terminated()

# 暂停上市股票列表
'''

    code:股票代码
    name:股票名称
    oDate:上市日期
    tDate:暂停上市日期

'''
ts.get_suspended()
def get_suspended_info(file_path):
    suspended_info = ts.get_suspended()
    suspended_info.to_csv(file_path, encoding='utf-8')
    print '\ndownload suspended info finished\n'
Exemple #29
0
def classification_type(class_types):
    if class_types == 'classification_industry':
        industry_classified = ts.get_industry_classified('sw')
        industry_classified.to_sql('classification_industry',
                                   engine,
                                   flavor='mysql',
                                   if_exists='replace')
    elif class_types == 'concept':
        concept_classified = ts.get_concept_classified()
        concept_classified.to_sql('classification_concept',
                                  engine,
                                  flavor='mysql',
                                  if_exists='replace')
    elif class_types == 'area':
        area_classified = ts.get_area_classified()
        area_classified.to_sql('classification_area',
                               engine,
                               flavor='mysql',
                               if_exists='replace')
    elif class_types == 'sme':
        sme_classified = ts.get_sme_classified()
        sme_classified.to_sql('classification_sme',
                              engine,
                              flavor='mysql',
                              if_exists='replace')
    elif class_types == 'gem':
        gem_classified = ts.get_gem_classified()
        gem_classified.to_sql('classification_gem',
                              engine,
                              flavor='mysql',
                              if_exists='replace')
    elif class_types == 'st':
        st_classified = ts.get_st_classified()
        st_classified.to_sql('classification_st',
                             engine,
                             flavor='mysql',
                             if_exists='replace')
    elif class_types == 'hs300':
        hs300s = ts.get_hs300s()
        hs300s.to_sql('classification_hs300s',
                      engine,
                      flavor='mysql',
                      if_exists='replace')
    elif class_types == 'sz50':
        sz50s = ts.get_sz50s()
        sz50s.to_sql('classification_sz50s',
                     engine,
                     flavor='mysql',
                     if_exists='replace')
    elif class_types == 'zz500':
        zz500s = ts.get_zz500s()
        zz500s.to_sql('classification_zz500s',
                      engine,
                      flavor='mysql',
                      if_exists='replace')
    elif class_types == 'terminated':
        terminated = ts.get_terminated()
        terminated.to_sql('classification_terminated',
                          engine,
                          flavor='mysql',
                          if_exists='replace')
    elif class_types == 'suspended':
        suspended = ts.get_suspended()
        suspended.to_sql('classification_suspended',
                         engine,
                         flavor='mysql',
                         if_exists='replace')
 def getSuspended(self):
     file_name = 'suspended.csv'
     path = self.index + self.index_suspended_class + file_name
     data = ts.get_suspended()
     data.to_csv(path, encoding='utf-8')
     print(file_name)
Exemple #31
0
def job_3():
    try:
        print("I'm working......股票分类数据")
        # 行业分类
        industry_classified = ts.get_industry_classified()
        data = pd.DataFrame(industry_classified)
        data.to_sql('industry_classified',engine,index=True,if_exists='replace')
        print("行业分类......done")

        # 概念分类
        concept_classified = ts.get_concept_classified()
        data = pd.DataFrame(concept_classified)
        data.to_sql('concept_classified',engine,index=True,if_exists='replace')
        print("概念分类......done")

        # 地域分类
        area_classified = ts.get_area_classified()
        data = pd.DataFrame(area_classified)
        data.to_sql('area_classified',engine,index=True,if_exists='replace')
        print("地域分类......done")

        # 中小板分类
        sme_classified = ts.get_sme_classified()
        data = pd.DataFrame(sme_classified)
        data.to_sql('sme_classified',engine,index=True,if_exists='replace')
        print("中小板分类......done")

        # 创业板分类
        gem_classified = ts.get_gem_classified()
        data = pd.DataFrame(gem_classified)
        data.to_sql('gem_classified',engine,index=True,if_exists='replace')
        print("创业板分类......done")

        # # 风险警示板分类
        # st_classified = ts.get_st_classified()
        # data = pd.DataFrame(st_classified)
        # data.to_sql('st_classified',engine,index=True,if_exists='replace')
        # print("风险警示板分类......done")

        # 沪深300成份及权重
        hs300s = ts.get_hs300s()
        data = pd.DataFrame(hs300s)
        data.to_sql('hs300s',engine,index=True,if_exists='replace')
        print("沪深300成份及权重......done")

        # 上证50成份股
        sz50s = ts.get_sz50s()
        data = pd.DataFrame(sz50s)
        data.to_sql('sz50s',engine,index=True,if_exists='replace')
        print("上证50成份股......done")

        # 中证500成份股
        zz500s = ts.get_zz500s()
        data = pd.DataFrame(zz500s)
        data.to_sql('zz500s',engine,index=True,if_exists='replace')
        print("中证500成份股......done")

        # 终止上市股票列表
        terminated = ts.get_terminated()
        data = pd.DataFrame(terminated)
        data.to_sql('terminated',engine,index=True,if_exists='replace')
        print("终止上市股票列表......done")

        # 暂停上市股票列表
        suspended = ts.get_suspended()
        data = pd.DataFrame(suspended)
        data.to_sql('suspended',engine,index=True,if_exists='replace')
        print("暂停上市股票列表......done")
    except Exception as e:
        print(e)
Exemple #32
0
import tushare as ts
import storage as storage

storage.save_sql(ts.get_industry_classified(), "basics/industry_classified")
storage.save_sql(ts.get_concept_classified(), "basics/concept_classified")
storage.save_sql(ts.get_area_classified(), "basics/area_classified")
storage.save_sql(ts.get_st_classified(), "basics/st_classified")
storage.save_sql(ts.get_hs300s(), "basics/hs300s")
storage.save_sql(ts.get_sz50s(), "basics/sz50s")
storage.save_sql(ts.get_zz500s(), "basics/zz500s")
storage.save_sql(ts.get_terminated(), "basics/terminated")
storage.save_sql(ts.get_suspended(), "basics/suspended")
storage.save_sql(ts.get_sme_classified(), "basics/sme_classified")
storage.save_sql(ts.get_gem_classified(), "basics/gem_classified")
 def stock_list_update(self,type='all'):
     '''
     股票基本面板更新
     :param type:
     :return:
     '''
     type_list =['all',
                 'industry',
                 'concept',
                 'area',
                 'sme',
                 'gem',
                 'st',
                 'hs300s',
                 'ss50s',
                 'zz500s',
                 'terminated',
                 'suspended']
     #输入类型检查
     if not isinstance(type,str):
         raise TypeError,'stock_type must be string'
     elif isinstance(type,str) and type not in type_list:
         raise ValueError,'%s is not a valid type' % (type)
     #更新数据
     if type == 'all':
         temp = ts.get_stock_basics()
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'global.csv')
         temp.to_csv(path)
         return temp
     if type == 'industry':
         temp = ts.get_industry_classified()
         #temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'industry.csv')
         temp.to_csv(path)
     if type == 'concept':
         temp = ts.get_concept_classified()
         #temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'concept.csv')
         temp.to_csv(path)
     if type == 'area':
         temp = ts.get_area_classified()
         #temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'area.csv')
         temp.to_csv(path)
     if type == 'sme':
         temp = ts.get_sme_classified()
         #temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'sme.csv')
         temp.to_csv(path)
     if type == 'gem':
         temp = ts.get_gem_classified()
         #temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'gem.csv')
         temp.to_csv(path)
     if type == 'st':
         temp = ts.get_st_classified()
         # temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'st.csv')
         temp.to_csv(path)
     if type == 'hs300s':
         temp = ts.get_hs300s()
         temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'hs300s.csv')
         temp.to_csv(path)
     if type == 'sz50s':
         temp = ts.get_sz50s()
         temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'sz50s.csv')
         temp.to_csv(path)
     if type == 'zz500s':
         temp = ts.get_zz500s()
         temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'zz500s.csv')
         temp.to_csv(path)
     if type == 'terminated':
         temp = ts.get_terminated()
         temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'terminated.csv')
         temp.to_csv(path)
     if type == 'suspended':
         temp = ts.get_suspended()
         temp['name'] = temp['name'].map(lambda x: x.encode('utf-8'))
         path = os.path.join(StockDataControler().stock_basis_init(),
                             'suspended.csv')
         temp.to_csv(path)
Exemple #34
0
def init(engine, session):
	tsl.log("stock_industry start...")
	df = ts.get_industry_classified()
	df.to_sql('stock_industry',engine,if_exists='replace')
	print
	tsl.log("stock_industry done")

	tsl.log("stock_concept start...")
	df = ts.get_concept_classified()
	df.to_sql('stock_concept',engine,if_exists='replace')
	print
	tsl.log("stock_concept done")

	tsl.log("stock_area start...")
	df = ts.get_area_classified()
	df.to_sql('stock_area',engine,if_exists='replace')
	tsl.log("stock_area done")

	tsl.log("stock_sme start...")
	df = ts.get_sme_classified()
	df.to_sql('stock_sme',engine,if_exists='replace')
	tsl.log("stock_sme done")

	tsl.log("stock_gem start...")
	df = ts.get_gem_classified()
	df.to_sql('stock_gem',engine,if_exists='replace')
	tsl.log("stock_gem done")

	tsl.log("stock_risk_warning start...")
	df = ts.get_st_classified()
	df.to_sql('stock_risk_warning',engine,if_exists='replace')
	tsl.log("stock_risk_warning done")

	tsl.log("stock_hs300 start...")
	df = ts.get_hs300s()
	df.to_sql('stock_hs300',engine,if_exists='replace')
	tsl.log("stock_hs300 done")

	tsl.log("stock_sz50 start...")
	df = ts.get_sz50s()
	df.to_sql('stock_sz50',engine,if_exists='replace')
	tsl.log("stock_sz50 done")

	tsl.log("stock_zz500 start...")
	df = ts.get_zz500s()
	df.to_sql('stock_zz500',engine,if_exists='replace')
	tsl.log("stock_zz500 done")

	tsl.log("stock_stop_list start...")
	df = ts.get_terminated()
	df.to_sql('stock_stop_list',engine,if_exists='replace')
	tsl.log("stock_stop_list done")

	tsl.log("stock_pause_list start...")
	df = ts.get_suspended()
	df.to_sql('stock_pause_list',engine,if_exists='replace')
	tsl.log("stock_pause_list done")
	
	tsl.log("call update_stock_info start...")
	session.execute('call update_stock_info')
	tsl.log("call update_stock_info done")
Exemple #35
0
    selectab = re.compile(r'\w*\w*')
    tabnames = selectab.findall(str(tables))
    res = tab_name in tabnames
    return res


stk_concept_class = ts.get_concept_classified()
stk_area_class = ts.get_area_classified()
stk_sme_class = ts.get_sme_classified()
stk_gem_class = ts.get_gem_classified()
stk_st_class = ts.get_st_classified()
stk_hs300_class = ts.get_hs300s()
stk_sz50_class = ts.get_sz50s()
stk_zz500_class = ts.get_zz500s()
stk_terminated_class = ts.get_terminated()
stk_sus_class = ts.get_suspended()

while True:
    #hostname = input('Please enter the hostname: ')
    pw = input('Please enter the password: '******'Please enter the number of datebase: ')
    try:
        conn = mysql.connector.connect(host='10.23.0.2',
                                       port=3306,
                                       user='******',
                                       password=pw,
                                       database=dbname)
        cur = conn.cursor()
        break
    except:
        re_try = input(