按日导入明细数

# -*- coding: utf-8 -*-
import tushare as ts
import os
import re
from sqlalchemy import create_engine
import cx_Oracle
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'


#stockname = sys.argv[1]
startdate = sys.argv[1]
enddate = sys.argv[2]


print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
#print stockname
print startdate
print enddate




sql="select substr(the_date,0,4)||'-'||substr(the_date,5,2)||'-'||substr(the_date,7,2) num,the_date from time_dimension t where the_date >=" + startdate + " and the_date <= " + enddate + " order by the_date "
sql1="select stockcode from mb_basic_stock_info where is_stock = 1 "
print sql
engine = create_engine('oracle+cx_oracle://C##stock:[email protected]:1521/orcl')
cnx = engine.connect()


index = 0
for stock in cnx.execute(sql1):
    stockname = stock[index]
    if stockname != "":
        if stockname != "":
            for row in cnx.execute(sql):
                t_date = row.num
                print t_date
                df = ts.get_tick_data(code=stockname,date=t_date)
                df.index.names = ['op_index']
                df['STOCKID']= stockname
                df['T_DATE']=t_date
#                df.to_sql('DW_TICKSTOCK_D_TEMP_HIS',cnx,if_exists='append',chunksize=1000)
                df.to_csv('/root/stock_py/data/data_stock/'+stockname+t_date+'.txt')
                os.system('sqlldr C##stock/password@orcl control=/root/stock_py/import/imp_stock.ctl data=/root/stock_py/data/data_stock/'+stockname+t_date+'.txt log=/root/stock_py/import/imp_stock_log.txt')
index +=1
cnx.close()

你可能感兴趣的:(股票)