Example #1
0
def get_gdp_contrib():
    try:
        df = ts.get_gdp_contrib()
        engine = create_engine('mysql://*****:*****@127.0.0.1/stock?charset=utf8')
        df.to_sql('gdp_contrib', engine, if_exists='append')
        print "message"
    except Exception, e:
        e.message
Example #2
0
def get_gdp_contrib_info():
    df = ts.get_gdp_contrib()
    if df is not None:
        res = df.to_sql(microE_gdp_contrib, engine, if_exists='replace')
        msg = 'ok' if res is None else res
        print('获取三大产业贡献率: ' + msg + '\n')
    else:
        print('获取三大产业贡献率: ' + 'None' + '\n')
Example #3
0
def stat_all(tmp_datetime):
    # 存款利率
    data = ts.get_deposit_rate()
    common.insert_db(data, "ts_deposit_rate", False, "`date`,`deposit_type`")

    # 贷款利率
    data = ts.get_loan_rate()
    common.insert_db(data, "ts_loan_rate", False, "`date`,`loan_type`")

    # 存款准备金率
    data = ts.get_rrr()
    common.insert_db(data, "ts_rrr", False, "`date`")

    # 货币供应量
    data = ts.get_money_supply()
    common.insert_db(data, "ts_money_supply", False, "`month`")

    # 货币供应量(年底余额)
    data = ts.get_money_supply_bal()
    common.insert_db(data, "ts_money_supply_bal", False, "`year`")

    # 国内生产总值(年度)
    data = ts.get_gdp_year()
    common.insert_db(data, "ts_gdp_year", False, "`year`")

    # 国内生产总值(季度)
    data = ts.get_gdp_quarter()
    common.insert_db(data, "ts_get_gdp_quarter", False, "`quarter`")

    # 三大需求对GDP贡献
    data = ts.get_gdp_for()
    common.insert_db(data, "ts_gdp_for", False, "`year`")

    # 三大产业对GDP拉动
    data = ts.get_gdp_pull()
    common.insert_db(data, "ts_gdp_pull", False, "`year`")

    # 三大产业贡献率
    data = ts.get_gdp_contrib()
    common.insert_db(data, "ts_gdp_contrib", False, "`year`")

    # 居民消费价格指数
    data = ts.get_cpi()
    common.insert_db(data, "ts_cpi", False, "`month`")

    # 工业品出厂价格指数
    data = ts.get_ppi()
    common.insert_db(data, "ts_ppi", False, "`month`")

    #############################基本面数据 http://tushare.org/fundamental.html
    # 股票列表
    data = ts.get_stock_basics()
    print(data.index)
    common.insert_db(data, "ts_stock_basics", True, "`code`")
Example #4
0
File: stock.py Project: ccfr32/www
 def return_gdp_contrib(self):
     '''
     三大产业贡献率
     '''
     df = ts.get_gdp_contrib()
     detail = {}
     for col in df.columns:
         lt = df[col].values.tolist()
         lt.reverse()
         detail[col] = lt
     self.reply(detail=detail)
Example #5
0
def get_macro():
    Macro={}
    Macro['Depo']=ts.get_deposit_rate()
    Macro['Loan']=ts.get_loan_rate()
    Macro['RRR']=ts.get_rrr()
    Macro['MoneySupply']=ts.get_money_supply()
    Macro['MoneyBalance']=ts.get_money_supply_bal()
    Macro['GDPYOY']=ts.get_gdp_year()
    Macro['GDPQOQ']=ts.get_gdp_quarter()
    Macro['GDPFOR']=ts.get_gdp_for()
    Macro['GDPPULL']=ts.get_gdp_pull()
    Macro['GDPCON']=ts.get_gdp_contrib()
    Macro['CPI']=ts.get_cpi()
    Macro['PPI']=ts.get_ppi()
    Macro['SHIBO']=ts.shibor_data()
    return Macro
Example #6
0
def get_gdp_three_industry_contrib():
    """三大产业贡献率"""
    logger.info('Begin get GdpThreeIndustryContrib.')
    try:
        data_df = ts.get_gdp_contrib()
    except Exception as e:
        logger.exception('Error get GdpThreeIndustryContrib.')
        return None
    else:
        data_dicts = []
        if data_df.empty:
            logger.warn('Empty get GdpThreeIndustryContrib.')
        else:
            data_dicts = [{'year': row[0], 'gdp_yoy': row[1],
                           'pi': row[2], 'si': row[3], 'industry': row[4],
                           'ti': row[5]}
                          for row in data_df.values]
            logger.info('Success get GdpThreeIndustryContrib.')
        return data_dicts
 def __call__(self, conns):
     self.base = Base()
     self.financial_data = conns['financial_data']
     '''存款利率'''
     deposit_rate = ts.get_deposit_rate()
     self.base.batchwri(deposit_rate, 'deposit_rate', self.financial_data)
     '''贷款利率'''
     loan_rate = ts.get_loan_rate()
     self.base.batchwri(loan_rate, 'loan_rate', self.financial_data)
     '''存款准备金率'''
     rrr = ts.get_rrr()
     self.base.batchwri(rrr, 'RatioOfDeposit', self.financial_data)
     '''货币供应量'''
     money_supply = ts.get_money_supply()
     self.base.batchwri(money_supply, 'money_supply', self.financial_data)
     '''货币供应量(年底余额)'''
     money_supply_bal = ts.get_money_supply_bal()
     self.base.batchwri(money_supply_bal, 'money_supply_bal',
                        self.financial_data)
     '''国内生产总值(年度)'''
     gdp_year = ts.get_gdp_year()
     self.base.batchwri(gdp_year, 'gdp_year', self.financial_data)
     '''国内生产总值(季度)'''
     gdp_quarter = ts.get_gdp_quarter()
     self.base.batchwri(gdp_quarter, 'gdp_quarter', self.financial_data)
     '''三大需求对GDP贡献'''
     gdp_for = ts.get_gdp_for()
     self.base.batchwri(gdp_for, 'gdp_for', self.financial_data)
     '''三大产业对GDP拉动'''
     gdp_pull = ts.get_gdp_pull()
     self.base.batchwri(gdp_pull, 'gdp_pull', self.financial_data)
     '''三大产业贡献率'''
     gdp_contrib = ts.get_gdp_contrib()
     self.base.batchwri(gdp_contrib, 'gdp_contrib', self.financial_data)
     '''居民消费价格指数'''
     cpi = ts.get_cpi()
     self.base.batchwri(cpi, 'cpi', self.financial_data)
     '''工业品出场价格指数'''
     ppi = ts.get_ppi()
     self.base.batchwri(ppi, 'ppi', self.financial_data)
Example #8
0
 def getGDPContrib(self):
     file_name = 'gdp_contrib.csv'
     path = self.index + self.index_gdp_contrib + file_name
     data = ts.get_gdp_contrib()
     data.to_csv(path, encoding='utf-8')
     print(file_name)
Example #9
0
    money_supply=ts.get_money_supply()
    money_supply.to_csv('D:\\ts\\macro\\money_supply.csv', encoding='gbk')

    money_supply_bal=ts.get_money_supply_bal()
    money_supply_bal.to_csv('D:\\ts\\macro\\money_supply_bal.csv', encoding='gbk')

    gdp_year=ts.get_gdp_year()
    gdp_year.to_csv('D:\\ts\\macro\\gdp_year.csv', encoding='gbk')

    gdp_quater=ts.get_gdp_quarter()
    gdp_quater.to_csv('D:\\ts\\macro\\gdp_quater.csv', encoding='gbk')

    gdp_for=ts.get_gdp_for()
    gdp_for.to_csv('D:\\ts\\macro\\gdp_for.csv', encoding='gbk')

    gdp_pull=ts.get_gdp_pull()
    gdp_pull.to_csv('D:\\ts\\macro\\gdp_pull.csv', encoding='gbk')

    gdp_contrib=ts.get_gdp_contrib()
    gdp_contrib.to_csv('D:\\ts\\macro\\gdp_contrib.csv', encoding='gbk')

    cpi=ts.get_cpi()
    cpi.to_csv('D:\\ts\\macro\\cpi.csv', encoding='gbk')


    ppi=ts.get_ppi()
    ppi.to_csv('D:\\ts\\macro\\ppi.csv', encoding='gbk')

    print 'all done'

Example #10
0
def capture_stock_data():
    capture_date = datetime.datetime.now().strftime("%Y%m%d")
    save_dir = "/home/dandelion/stock_data/" + capture_date

    if not os.path.exists(save_dir):
        os.mkdir(save_dir)
        print("The save directory is created successfully!\n", save_dir)
    print("The save directory is already exist!\n", save_dir)
    # ======================Daily Command================================================================
    # get the boxoffcie data of the last day and save as csvfile named as the capture command
    ts.day_boxoffice().to_csv(
        save_dir + "/" + capture_date + "_day_boxoffice.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("day_boxoffice data capture completed!")

    # get the cinema data of the last day and save as csvfile named as the capture command
    ts.day_cinema().to_csv(
        save_dir + "/" + capture_date + "_day_cinema.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("day_cinema data capture completed!")

    ts.month_boxoffice().to_csv(
        save_dir + "/" + capture_date + "_month_boxoffice.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("month_boxoffice data capture completed!")

    ts.realtime_boxoffice().to_csv(
        save_dir + "/" + capture_date + "_realtime_boxoffice.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("realtime_boxoffice data capture completed!")

    # get the stock data index of the last day and save as csvfile named as the capture command
    ts.get_index().to_csv(
        save_dir + "/" + capture_date + "_get_index.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_index data capture completed!")

    # get the history cpi data and save as csvfile named as the capture command
    ts.get_cpi().to_csv(
        save_dir + "/" + capture_date + "_get_cpi.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_cpi data capture completed!")

    # get the history gdp data  by month and save as csvfile named as the capture command
    ts.get_gdp_year().to_csv(
        save_dir + "/" + capture_date + "_get_gdp_year.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_gdp_year data capture completed!")

    # get today all stock data and save as csvfile named as the capture command
    # ts.get_today_all().to_csv(save_dir+'/'+capture_date+'_get_today_all.csv',header=True,sep=',',index=False)

    # get detail information of the top brokers today and save as csvfile named as the capture command
    ts.broker_tops().to_csv(
        save_dir + "/" + capture_date + "_broker_tops.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("broker_tops data capture completed!")

    # get detail information of the top brokers today and save as csvfile named as the capture command
    ts.cap_tops().to_csv(
        save_dir + "/" + capture_date + "_cap_tops.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("cap_tops data capture completed!")

    ts.get_area_classified().to_csv(
        save_dir + "/" + capture_date + "_get_area_classified.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_area_classified data capture completed!")

    # ts.get_balance_sheet(code='').to_csv(save_dir+'/'+capture_date+'_get_balance_sheet.csv',header=True,sep=',',index=False)
    # print('get_balance_sheet data capture completed!')

    # ts.get_cash_flow(code='').to_csv(save_dir+'/'+capture_date+'_get_cash_flow.csv',header=True,sep=',',index=False)
    # print('get_cash_flow data capture completed!')

    ts.get_day_all().to_csv(
        save_dir + "/" + capture_date + "_get_day_all.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_day_all data capture completed!")
    ts.get_cashflow_data(2018, 3).to_csv(
        save_dir + "/" + capture_date + "_get_cashflow_data.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_cashflow_data data capture completed!")
    ts.get_concept_classified().to_csv(
        save_dir + "/" + capture_date + "_get_concept_classified.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_concept_classified data capture completed!")
    ts.get_debtpaying_data(2018, 3).to_csv(
        save_dir + "/" + capture_date + "_get_debtpaying_data.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_debtpaying_data data capture completed!")
    ts.get_deposit_rate().to_csv(
        save_dir + "/" + capture_date + "_get_deposit_rate.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_deposit_rate data capture completed!")

    ts.get_gdp_contrib().to_csv(
        save_dir + "/" + capture_date + "_get_gdp_contrib.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_gdp_for().to_csv(
        save_dir + "/" + capture_date + "_get_gdp_for.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_gdp_pull().to_csv(
        save_dir + "/" + capture_date + "_get_gdp_pull.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_gdp_quarter().to_csv(
        save_dir + "/" + capture_date + "_get_gdp_quarter.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("get_gdp_ data capture completed!")
    # ts.get_gdp_year().to_csv(save_dir+'/'+capture_date+'_get_gdp_year.csv',header=True,sep=',',index=False)
    ts.get_gem_classified().to_csv(
        save_dir + "/" + capture_date + "_get_gem_classified.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_gold_and_foreign_reserves().to_csv(
        save_dir + "/" + capture_date + "_get_gold_and_foreign_reserves.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_growth_data(2018, 3).to_csv(
        save_dir + "/" + capture_date + "_get_growth_data.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_industry_classified().to_csv(
        save_dir + "/" + capture_date + "_get_industry_classified.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_hs300s().to_csv(
        save_dir + "/" + capture_date + "_get_hs300s.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_sz50s().to_csv(
        save_dir + "/" + capture_date + "_get_sz50s.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_zz500s().to_csv(
        save_dir + "/" + capture_date + "_get_zz500s.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_operation_data(2018, 3).to_csv(
        save_dir + "/" + capture_date + "_get_operation_data.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_stock_basics().to_csv(
        save_dir + "/" + capture_date + "_get_stock_basics.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.get_report_data(2018, 3).to_csv(
        save_dir + "/" + capture_date + "_get_report_data.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.inst_detail().to_csv(
        save_dir + "/" + capture_date + "_inst_detail.csv",
        header=True,
        sep=",",
        index=False,
    )
    ts.inst_tops().to_csv(
        save_dir + "/" + capture_date + "_inst_tops.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("inst_tops data capture completed!")
    ts.new_stocks().to_csv(
        save_dir + "/" + capture_date + "_new_stocks.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("new_stocks data capture completed!")
    ts.top_list().to_csv(
        save_dir + "/" + capture_date + "_top_list.csv",
        header=True,
        sep=",",
        index=False,
    )
    print("top_list data capture completed!")
Example #11
0
def gdp_contribute():
    return ts.get_gdp_contrib()
Example #12
0
 def setGdpContrib(self, isSave=False, tableName=MACROECONOMIC_GDP_CONTRIB):
     df = ts.get_gdp_contrib()
     if isSave is True:
         df.to_sql(tableName, self.engine_sql, if_exists='append')
     return df
Example #13
0
def getgdpcontribdb():
	gdpcontrib = ts.get_gdp_contrib()
	gdpcontrib.to_sql('gdpcontrib_data',ENGINE,if_exists = 'append')
Example #14
0
def init(engine, session):
	tbl = "macro_deposit"
	tsl.log(tbl + " start...")
	df = ts.get_deposit_rate()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_loan"
	tsl.log(tbl + " start...")
	df = ts.get_loan_rate()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_rrr"
	tsl.log(tbl + " start...")
	df = ts.get_rrr()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_money_supply"
	tsl.log(tbl + " start...")
	df = ts.get_money_supply()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_money_supply_year"
	tsl.log(tbl + " start...")
	df = ts.get_money_supply_bal()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_gdp_year"
	tsl.log(tbl + " start...")
	df = ts.get_gdp_year()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_gdp_quarter"
	tsl.log(tbl + " start...")
	df = ts.get_gdp_quarter()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_gdp_for"
	tsl.log(tbl + " start...")
	df = ts.get_gdp_for()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_gdp_pull"
	tsl.log(tbl + " start...")
	df = ts.get_gdp_pull()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_gdp_contrib"
	tsl.log(tbl + " start...")
	df = ts.get_gdp_contrib()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_cpi"
	tsl.log(tbl + " start...")
	df = ts.get_cpi()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "macro_ppi"
	tsl.log(tbl + " start...")
	df = ts.get_ppi()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
	
	tbl = "gold_and_foreign_reserves"
	tsl.log(tbl + " start...")
	df = ts.get_gold_and_foreign_reserves()
	df.to_sql(tbl,engine,if_exists='replace')
	tsl.log(tbl + " done")
Example #15
0
def macro_type(macros_type):
    if macros_type == 'deposit_rate':
        deposit_rate = ts.get_deposit_rate()
        if deposit_rate is not None:
            deposit_rate.to_sql('macros_deposit_rate',
                                engine,
                                flavor='mysql',
                                if_exists='replace')
    elif macros_type == 'loan_rate':
        loan_rate = ts.get_loan_rate()
        if loan_rate is not None:
            loan_rate.to_sql('macros_loan_rate',
                             engine,
                             flavor='mysql',
                             if_exists='replace')
    elif macros_type == 'rrr':
        rrr = ts.get_rrr()
        if rrr is not None:
            rrr.to_sql('macros_rrr',
                       engine,
                       flavor='mysql',
                       if_exists='replace')
    elif macros_type == 'money_supply':
        money_supply = ts.get_money_supply()
        if money_supply is not None:
            money_supply.to_sql('macros_money_supply',
                                engine,
                                flavor='mysql',
                                if_exists='replace')
    elif macros_type == 'money_supply_bal':
        money_supply_bal = ts.get_money_supply_bal()
        if money_supply_bal is not None:
            money_supply_bal.to_sql('macros_money_supply_bal',
                                    engine,
                                    flavor='mysql',
                                    if_exists='replace')
    elif macros_type == 'gdp_year':
        gdp_year = ts.get_gdp_year()
        if gdp_year is not None:
            gdp_year.to_sql('macros_gdp_year',
                            engine,
                            flavor='mysql',
                            if_exists='replace')
    elif macros_type == 'gdp_quater':
        gdp_quater = ts.get_gdp_quarter()
        if gdp_quater is not None:
            gdp_quater.to_sql('macros_gdp_quater',
                              engine,
                              flavor='mysql',
                              if_exists='replace')
    elif macros_type == 'gdp_for':
        gdp_for = ts.get_gdp_for()
        if gdp_for is not None:
            gdp_for.to_sql('macros_gdp_for',
                           engine,
                           flavor='mysql',
                           if_exists='replace')
    elif macros_type == 'gdp_pull':
        gdp_pull = ts.get_gdp_pull()
        if gdp_pull is not None:
            gdp_pull.to_sql('macros_gdp_pull',
                            engine,
                            flavor='mysql',
                            if_exists='replace')
    elif macros_type == 'gdp_contrib':
        gdp_contrib = ts.get_gdp_contrib()
        if gdp_contrib is not None:
            gdp_contrib.to_sql('macros_gdp_contrib',
                               engine,
                               flavor='mysql',
                               if_exists='replace')
    elif macros_type == 'cpi':
        cpi = ts.get_cpi()
        if cpi is not None:
            cpi.to_sql('macros_cpi',
                       engine,
                       flavor='mysql',
                       if_exists='replace')
    elif macros_type == 'ppi':
        ppi = ts.get_ppi()
        if ppi is not None:
            ppi.to_sql('macros_ppi',
                       engine,
                       flavor='mysql',
                       if_exists='replace')
Example #16
0
#货币供应量(年底余额)

m_supply_y = ts.get_money_supply_bal()

#GDP
gdp_y = ts.get_gdp_year()
gdp_q = ts.get_gdp_quarter()

#三大需求对GDP贡献
gdp_for = ts.get_gdp_for()

#三大产业对GDP拉动
gdp_pull = ts.get_gdp_pull()

#三大产业贡献率
gdp_contrib = ts.get_gdp_contrib()


cpi = ts.get_cpi()

ppi = ts.get_ppi()

df = ts.shibor_data() #取当前年份的数据
#df = ts.shibor_data(2014) #取2014年的数据
df.sort('date', ascending=False).head(10)

df = ts.shibor_quote_data() #取当前年份的数据
#df = ts.shibor_quote_data(2014) #取2014年的数据
df.sort('date', ascending=False).head(10)

#shibo均值
Example #17
0
def job_5():
    try:
        print("I'm working......宏观经济数据")
        # 存款利率
        deposit_rate = ts.get_deposit_rate()
        data = pd.DataFrame(deposit_rate)
        data.to_sql('deposit_rate',engine,index=True,if_exists='replace')
        print("存款利率......done")

        # 贷款利率
        loan_rate = ts.get_loan_rate()
        data = pd.DataFrame(loan_rate)
        data.to_sql('loan_rate',engine,index=True,if_exists='replace')
        print("贷款利率......done")

        # 存款准备金率
        rrr = ts.get_rrr()
        data = pd.DataFrame(rrr)
        data.to_sql('rrr',engine,index=True,if_exists='replace')
        print("存款准备金率......done")

        # 货币供应量
        money_supply = ts.get_money_supply()
        data = pd.DataFrame(money_supply)
        data.to_sql('money_supply',engine,index=True,if_exists='replace')
        print("货币供应量......done")

        # 货币供应量(年底余额)
        money_supply_bal = ts.get_money_supply_bal()
        data = pd.DataFrame(money_supply_bal)
        data.to_sql('money_supply_bal',engine,index=True,if_exists='replace')
        print("货币供应量(年底余额)......done")

        # 国内生产总值(年度)
        gdp_year = ts.get_gdp_year()
        data = pd.DataFrame(gdp_year)
        data.to_sql('gdp_year',engine,index=True,if_exists='replace')
        print("国内生产总值(年度)......done")

        # 国内生产总值(季度)
        gdp_quarter = ts.get_gdp_quarter()
        data = pd.DataFrame(gdp_quarter)
        data.to_sql('gdp_quarter',engine,index=True,if_exists='replace')
        print("国内生产总值(季度)......done")

        # 三大需求对GDP贡献
        gdp_for = ts.get_gdp_for()
        data = pd.DataFrame(gdp_for)
        data.to_sql('gdp_for',engine,index=True,if_exists='replace')
        print("三大需求对GDP贡献......done")

        # 三大产业对GDP拉动
        gdp_pull = ts.get_gdp_pull()
        data = pd.DataFrame(gdp_pull)
        data.to_sql('gdp_pull',engine,index=True,if_exists='replace')
        print("三大产业对GDP拉动......done")

        # 三大产业贡献率
        gdp_contrib = ts.get_gdp_contrib()
        data = pd.DataFrame(gdp_contrib)
        data.to_sql('gdp_contrib',engine,index=True,if_exists='replace')
        print("三大产业贡献率......done")

        # 居民消费价格指数
        cpi = ts.get_cpi()
        data = pd.DataFrame(cpi)
        data.to_sql('cpi',engine,index=True,if_exists='replace')
        print("居民消费价格指数......done")

        # 工业品出厂价格指数
        ppi = ts.get_ppi()
        data = pd.DataFrame(ppi)
        data.to_sql('ppi',engine,index=True,if_exists='replace')
        print("工业品出厂价格指数......done")

    except Exception as e:
        print(e)
Example #18
0
'''
ts.get_gdp_pull()
# 三大产业贡献率
'''
返回值说明:

    year :统计年度
    gdp_yoy :国内生产总值
    pi :第一产业献率(%)
    si :第二产业献率(%)
    industry:其中工业献率(%)
    ti :第三产业献率(%)

'''

ts.get_gdp_contrib()

# 居民消费价格指数
'''
返回值说明:
    month :统计月份
    cpi :价格指数
'''
ts.get_cpi()

# 工业品出厂价格指数
'''
返回值说明:

    month :统计月份
    ppiip :工业品出厂价格指数
def load_macro_economy():
    # 下载存款利率
    try:
        rs = ts.get_deposit_rate()
        pd.DataFrame.to_sql(rs, "deposit_rate", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载存款利率ok")
    except:
        print("下载存款利率出错")
    # 下载贷款利率
    try:
        rs = ts.get_loan_rate()
        pd.DataFrame.to_sql(rs, "loan_rate", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载贷款利率ok")
    except:
        print("下载贷款利率出错")
    # 下载存款准备金率
    try:
        rs = ts.get_rrr()
        pd.DataFrame.to_sql(rs, "rrr", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载存款准备金率ok")
    except:
        print("下载存款准备金率出错")
    # 下载货币供应量
    try:
        rs = ts.get_money_supply()
        pd.DataFrame.to_sql(rs, "money_supply", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载货币供应量ok")
    except:
        print("下载货币供应量出错")
    # 下载货币供应量(年底余额)
    try:
        rs = ts.get_money_supply_bal()
        pd.DataFrame.to_sql(
            rs, "money_supply_bal", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True
        )
        print("下载货币供应量(年底余额)ok")
    except:
        print("下载货币供应量(年底余额)出错")
    # 下载国内生产总值(年度)
    try:
        rs = ts.get_gdp_year()
        pd.DataFrame.to_sql(rs, "gdp_year", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载国内生产总值(年度)ok")
    except:
        print("下载国内生产总值(年度)出错")
    # 下载国内生产总值(季度)
    try:
        rs = ts.get_gdp_quarter()
        pd.DataFrame.to_sql(rs, "gdp_quarter", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载国内生产总值(季度)ok")
    except:
        print("下载国内生产总值(季度)出错")
    # 下载三大需求对GDP贡献
    try:
        rs = ts.get_gdp_for()
        pd.DataFrame.to_sql(rs, "gdp_for", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载三大需求对GDP贡献ok")
    except:
        print("下载三大需求对GDP贡献出错")
    # 下载三大产业对GDP拉动
    try:
        rs = ts.get_gdp_pull()
        pd.DataFrame.to_sql(rs, "gdp_pull", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载三大产业对GDP拉动ok")
    except:
        print("下载三大产业对GDP拉动出错")
    # 下载三大产业贡献率
    try:
        rs = ts.get_gdp_contrib()
        pd.DataFrame.to_sql(rs, "gdp_contrib", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载三大产业贡献率ok")
    except:
        print("下载三大产业贡献率出错")
    # 下载居民消费价格指数
    try:
        rs = ts.get_cpi()
        pd.DataFrame.to_sql(rs, "gdp_cpi", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载居民消费价格指数ok")
    except:
        print("下载居民消费价格指数出错")
    # 下载工业品出厂价格指数
    try:
        rs = ts.get_ppi()
        pd.DataFrame.to_sql(rs, "gdp_ppi", con=conn_macro_economy, flavor="mysql", if_exists="replace", index=True)
        print("下载工业品出厂价格指数ok")
    except:
        print("下载工业品出厂价格指数出错")