Пример #1
0
 def save_data(self, code, data):
     import_num = 0
     cod, exch = self.split_code(code)
     for i in data:
         if 'Open' in i:
             continue
         else:
             try:
                 da = i.strip().split(',')
                 if len(da) != 7:
                     print "the number of this line's data is wrong ", da
                     continue
                 else:
                     s = StockData.new()
                     s.code, s.exchange = cod, exch
                     s.Date = str(da[0])
                     s.Open = float(da[1])
                     s.High = float(da[2])
                     s.Low = float(da[3])
                     s.Close = float(da[4])
                     s.Volume = float(da[5])
                     s.AdjClose = float(da[6])
                     #print s
                     s.save()
                     import_num += 1
             except Exception, e:
                 print e, code, data
Пример #2
0
	def save_data(self, code, data):
		import_num = 0
		cod, exch = self.split_code(code)
		for i in data:
			if 'Open' in i:
				continue
			else:
				try:
					da = i.strip().split(',')
					if len(da) != 7:
						print "the number of this line's data is wrong ",da
						continue
					else:
						s = StockData.new()
						s.code,s.exchange = cod, exch
						s.Date = str(da[0])
						s.Open = float(da[1])
						s.High = float(da[2])
						s.Low = float(da[3])
						s.Close = float(da[4])
						s.Volume = float(da[5])
						s.AdjClose = float(da[6])
						#print s
						s.save()
						import_num += 1
				except Exception,e:
					print e,code,data
Пример #3
0
def init_data2db(fns, f_dir, start):
    #fns = ['table002367.sz','table200016.sz']
    filenum = 0
    num = 0
    all_file_num = ASharesCodeReal.mgr().get_len_codes()
    for f in fns:
        filenum += 1
        print f, "......   ", "%0.02f" % (
            100 * float(filenum) / float(all_file_num)
        ), "%", "......running time:", datetime.datetime.now() - start
        if len(f) == 21:  #wget下载的文件 (table.csv?s=000002.sz)
            code = f.strip()[12:18]
            exch = f.strip()[19:]
        elif len(f) == 14:  #urllib2下载的文件 (table600602.ss)
            code = f.strip()[5:11]
            exch = f.strip()[12:]
        else:
            print "ERROR filename doesn't match!"
            continue

        of = open('%s%s' % (f_dir, f), 'r')
        for i in of.readlines():  #文件行循环
            #if 'Open' not in i:				#去掉文件内容第一行
            if 'Open' in i:
                continue
            else:
                try:
                    data = i.strip().split(',')
                    s = StockData.new()
                    s.code = str(code)
                    s.exchange = str(exch)
                    s.Date = data[0]
                    s.Open = float(data[1])
                    s.High = float(data[2])
                    s.Low = float(data[3])
                    s.Close = float(data[4])
                    s.Volume = long(data[5])
                    s.AdjClose = float(data[6])
                    #print s
                    s.save()
                    num += 1
                except Exception, e:
                    print f
                    print s
                    print e
Пример #4
0
def init_data2db(fns, f_dir, start):
	#fns = ['table002367.sz','table200016.sz']
	filenum = 0
	num = 0
	all_file_num = ASharesCodeReal.mgr().get_len_codes()
	for f in fns:
		filenum += 1
		print f,"......   ","%0.02f"%(100*float(filenum)/float(all_file_num)),"%","......running time:",datetime.datetime.now()-start
		if len(f) == 21: #wget下载的文件 (table.csv?s=000002.sz)
			code = f.strip()[12:18]
			exch = f.strip()[19:]    
		elif len(f) == 14: #urllib2下载的文件 (table600602.ss)
			code = f.strip()[5:11]
			exch = f.strip()[12:]
		else:
			print "ERROR filename doesn't match!"
			continue    
		
		of = open('%s%s'%(f_dir,f),'r')
		for i in of.readlines():				#文件行循环
			#if 'Open' not in i:				#去掉文件内容第一行
			if 'Open' in i:
				continue
			else:
				try:
					data = i.strip().split(',')
					s = StockData.new()
					s.code = str(code)
					s.exchange = str(exch)
					s.Date = data[0]
					s.Open = float(data[1])
					s.High = float(data[2])
					s.Low = float(data[3])
					s.Close = float(data[4])
					s.Volume = long(data[5])
					s.AdjClose = float(data[6])
					#print s
					s.save()
					num += 1
				except Exception,e:
					print f
					print s
					print e