示例#1
0
def input_stock_data():
    res=db.select('select * from code_list')
    #string_list=[]
    for i in res:
        stock_code=i[u'code'].decode('utf-8')
        stock_num=stock_code.split('.')
        get_sd_csv('20010101','20150814',stock_num[0],'../stock_data/%s.csv'%stock_num[0])
        print stock_num[0]
示例#2
0
def input_stock_data():
    res = db.select('select * from code_list')
    #string_list=[]
    for i in res:
        stock_code = i[u'code'].decode('utf-8')
        stock_num = stock_code.split('.')
        get_sd_csv('20010101', '20150814', stock_num[0],
                   '../stock_data/%s.csv' % stock_num[0])
        print stock_num[0]
示例#3
0
def select_updata():
    stock_list = db.select('select * from code_list')

    for i in stock_list:
        stock_code = i[u'code'].decode('utf-8')
        stock_num = stock_code.split('.')
        rs = up_data('20150817', '20150817', stock_num[0])
        if '-1:No Data Returned' in rs:
            print '00'
        else:
            hs = rs.split(',')
            temp = []

            for index, i in enumerate(hs[20:]):
                if index == 0:
                    h = i.replace('PB\n', '')
                    temp.append(h.strip('\"'))
                elif index == 20:
                    temp.append(i.replace('\n', ''))
                else:
                    temp.append(i.strip('\"'))

            if temp[2]:
                only_key = '%s+%s' % (temp[0], temp[4])

                try:

                    n = db.update(
                        'insert into daily_data(secID, ticker , secShortName , exchangeCD , tradeDate , preClosePrice , actPreClosePrice ,openPrice , highestPrice , lowestPrice , closePrice , turnoverVol , turnoverValue , dealAmount , turnoverRate , accumAdjFactor ,negMarketValue , marketValue , PE ,PE1, PB, only_key) values(?, ? ,? ,? ,? ,? ,? ,? ,? ,?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? )',
                        temp[0], temp[1],
                        temp[2].decode('GB18030').encode('utf-8'),
                        temp[3], temp[4], float(temp[5]), float(temp[6]),
                        float(temp[7]), float(temp[8]), float(temp[9]),
                        float(temp[10]), int(temp[11]), float(temp[12]),
                        int(temp[13]), float(temp[14]), float(temp[15]),
                        float(temp[16]), float(temp[17]), float(temp[18]),
                        float(temp[19]), float(temp[20]), only_key)
                    print temp[2].decode('GB18030').encode('utf-8'), n
                    f = open('stock_list.txt', 'a')
                    f.write('%s,%s,%s\n' %
                            (temp[0], temp[1],
                             temp[2].decode('GB18030').encode('utf-8')))
                    f.close()
                except Exception as e:
                    print e

    print 'All stock updata done!'
示例#4
0
def input_daily_data():
    res = db.select('select * from code_list')
    #string_list=[]
    for i in res:
        stock_code = i[u'code'].decode('utf-8')
        stock_num = stock_code.split('.')
        stock_data = open_csv('../stock_data/%s.csv' % stock_num[0])
        try:
            for i in range(stock_data.shape[0]):
                only_key = '%s+%s' % (stock_data.iloc[i]['secID'],
                                      stock_data.iloc[i]['tradeDate'])
                charset = chardet.detect(stock_data.iloc[i]['secShortName'])
                print charset, stock_data.iloc[i]['secShortName'].decode(
                    'GB2312')
                n = db.update(
                    'insert into daily_data(secID, ticker , secShortName , exchangeCD , tradeDate , preClosePrice , actPreClosePrice ,openPrice , highestPrice , lowestPrice , closePrice , turnoverVol , turnoverValue , dealAmount , turnoverRate , accumAdjFactor ,negMarketValue , marketValue , PE ,PE1, PB, only_key) values(?, ? ,? ,? ,? ,? ,? ,? ,? ,?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? )',
                    stock_data.iloc[i]['secID'],
                    str(stock_data.iloc[i]['ticker']),
                    stock_data.iloc[i]['secShortName'].decode('GB2312').encode(
                        'utf-8'), stock_data.iloc[i]['exchangeCD'],
                    stock_data.iloc[i]['tradeDate'],
                    float(stock_data.iloc[i]['preClosePrice']),
                    float(stock_data.iloc[i]['actPreClosePrice']),
                    float(stock_data.iloc[i]['openPrice']),
                    float(stock_data.iloc[i]['highestPrice']),
                    float(stock_data.iloc[i]['lowestPrice']),
                    float(stock_data.iloc[i]['closePrice']),
                    int(stock_data.iloc[i]['turnoverVol']),
                    float(stock_data.iloc[i]['turnoverValue']),
                    int(stock_data.iloc[i]['dealAmount']),
                    float(stock_data.iloc[i]['turnoverRate']),
                    float(stock_data.iloc[i]['accumAdjFactor']),
                    float(stock_data.iloc[i]['negMarketValue']),
                    float(stock_data.iloc[i]['marketValue']),
                    float(stock_data.iloc[i]['PE']),
                    float(stock_data.iloc[i]['PE1']),
                    float(stock_data.iloc[i]['PB']), only_key)
                print n
            print '%s:插入完成' % stock_num[0]
        except Exception as e:
            print e
            f = open('log.txt', 'a')
            traceback.print_exc(file=f)
            f.flush()
            f.close()
示例#5
0
def input_daily_data():
    res=db.select('select * from code_list')
    #string_list=[]
    for i in res:
        stock_code=i[u'code'].decode('utf-8')
        stock_num=stock_code.split('.')
        stock_data=open_csv('../stock_data/%s.csv'%stock_num[0])
        try:
            for i in range(stock_data.shape[0]):
                only_key='%s+%s'%(stock_data.iloc[i]['secID'],stock_data.iloc[i]['tradeDate'])
                charset=chardet.detect(stock_data.iloc[i]['secShortName'])
                print charset,stock_data.iloc[i]['secShortName'].decode('GB2312')
                n = db.update('insert into daily_data(secID, ticker , secShortName , exchangeCD , tradeDate , preClosePrice , actPreClosePrice ,openPrice , highestPrice , lowestPrice , closePrice , turnoverVol , turnoverValue , dealAmount , turnoverRate , accumAdjFactor ,negMarketValue , marketValue , PE ,PE1, PB, only_key) values(?, ? ,? ,? ,? ,? ,? ,? ,? ,?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? )',stock_data.iloc[i]['secID'],  str(stock_data.iloc[i]['ticker']) ,stock_data.iloc[i]['secShortName'].decode('GB2312').encode('utf-8'), stock_data.iloc[i]['exchangeCD'] , stock_data.iloc[i]['tradeDate'] , float(stock_data.iloc[i]['preClosePrice']) , float(stock_data.iloc[i]['actPreClosePrice']) ,float(stock_data.iloc[i]['openPrice']) , float(stock_data.iloc[i]['highestPrice']) , float(stock_data.iloc[i]['lowestPrice']) , float(stock_data.iloc[i]['closePrice']) , int(stock_data.iloc[i]['turnoverVol']) , float(stock_data.iloc[i]['turnoverValue']) , int(stock_data.iloc[i]['dealAmount']) , float(stock_data.iloc[i]['turnoverRate']) , float(stock_data.iloc[i]['accumAdjFactor']) , float(stock_data.iloc[i]['negMarketValue']) , float(stock_data.iloc[i]['marketValue']) , float(stock_data.iloc[i]['PE']) , float(stock_data.iloc[i]['PE1']), float(stock_data.iloc[i]['PB']),only_key)
                print n
            print '%s:插入完成'%stock_num[0]
        except Exception as e:
            print e 
            f=open('log.txt','a')
            traceback.print_exc(file=f)   
            f.flush()   
            f.close()   
示例#6
0
def select_updata():
    stock_list=db.select('select * from code_list')
   
    
    for i in stock_list:
        stock_code=i[u'code'].decode('utf-8')
        stock_num=stock_code.split('.')
        rs=up_data('20150817', '20150817', stock_num[0])
        if '-1:No Data Returned' in rs:
            print '00'
        else:
            hs=rs.split(',')
            temp=[]
            
            for index,i in enumerate(hs[20:]):
                if index==0:
                    h=i.replace('PB\n','')
                    temp.append(h.strip('\"'))
                elif index==20:
                    temp.append(i.replace('\n',''))
                else:
                    temp.append(i.strip('\"'))
    
              
            
            if temp[2] :  
                only_key='%s+%s'%(temp[0],temp[4])
                
                try:
                
                    n=db.update('insert into daily_data(secID, ticker , secShortName , exchangeCD , tradeDate , preClosePrice , actPreClosePrice ,openPrice , highestPrice , lowestPrice , closePrice , turnoverVol , turnoverValue , dealAmount , turnoverRate , accumAdjFactor ,negMarketValue , marketValue , PE ,PE1, PB, only_key) values(?, ? ,? ,? ,? ,? ,? ,? ,? ,?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? )',temp[0],  temp[1] ,temp[2].decode('GB18030').encode('utf-8'), temp[3] , temp[4] , float(temp[5]) , float(temp[6]) ,float(temp[7]) , float(temp[8]) , float(temp[9]) , float(temp[10]) , int(temp[11]) , float(temp[12]) , int(temp[13]) , float(temp[14]) , float(temp[15]) , float(temp[16]) , float(temp[17]) , float(temp[18]) , float(temp[19]), float(temp[20]),only_key)
                    print temp[2].decode('GB18030').encode('utf-8'),n
                    f=open('stock_list.txt','a')
                    f.write('%s,%s,%s\n'%(temp[0],temp[1],temp[2].decode('GB18030').encode('utf-8')))
                    f.close()
                except Exception as e:
                    print e
        
        
    print 'All stock updata done!'