python 股票交易数据按名称 开户时间 结束时间入库

    xiaoxiao2021-03-25  292

    # -*- 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[2] enddate = sys.argv[3]   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 " print sql engine = create_engine('oracle+cx_oracle://stock:stock@192.168.1.10:1521/orcl') cnx = engine.connect() 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',cnx,if_exists='append',chunksize=100) cnx.close()
    转载请注明原文地址: https://ju.6miu.com/read-142.html

    最新回复(0)