Exemplo n.º 1
0
def get_gdp_quarter():
    try:
        df = ts.get_gdp_quarter()
        engine = create_engine('mysql://root:[email protected]/stock?charset=utf8')
        df.to_sql('gdp_quarter', engine, if_exists='append')
        print "message"
    except Exception, e:
        e.message
Exemplo n.º 2
0
Arquivo: stock.py Projeto: ccfr32/www
 def return_gdp_quarter(self):
     '''
     gdp(季度)
     '''
     df = ts.get_gdp_quarter()
     df = df[df['quarter'] >= 1990]
     detail = {}
     for col in df.columns:
         lt = df[col].values.tolist()
         lt.reverse()
         for idx in xrange(0, len(lt)):
             if math.isnan(lt[idx]):
                 lt[idx] = None
         detail[col] = lt
     self.reply(detail=detail)
Exemplo n.º 3
0
    loan_rate=ts.get_loan_rate()
    loan_rate.to_csv('D:\\ts\\macro\\loan_rate.csv', encoding='gbk')

    rrr=ts.get_rrr()
    rrr.to_csv('D:\\ts\\macro\\rrr.csv', encoding='gbk')

    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')

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("下载工业品出厂价格指数出错")