예제 #1
0
	def start_fetching(self, start, end, period, pro_start_time):
		code_num = 0
		data = ''
		code_list = ASharesCodeReal.mgr().get_all_codes()
		num_all = len(code_list)
		for code in code_list:
			url = self.generate_url(code,start,end,period)				
			try:
				data = self.fetch_data(url)
			except Exception, e:
				print code,e				
			if data:
				import_num = self.save_data(code,data)
				print self.progress_bar(code,len(code_list),code_num,pro_start_time)
				code_num += 1
예제 #2
0
 def start_fetching(self, start, end, period, pro_start_time):
     code_num = 0
     data = ''
     code_list = ASharesCodeReal.mgr().get_all_codes()
     num_all = len(code_list)
     for code in code_list:
         url = self.generate_url(code, start, end, period)
         try:
             data = self.fetch_data(url)
         except Exception, e:
             print code, e
         if data:
             import_num = self.save_data(code, data)
             print self.progress_bar(code, len(code_list), code_num,
                                     pro_start_time)
             code_num += 1
예제 #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
예제 #5
0
def data2db(fns):
	for f in fns:
		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			

		s = ASharesCodeReal.new()
		try:
			s.code = str(code)
			s.exchange = str(exch)
			s.status = 'valid'
			#print s
			s.save()
		except Exception,e:
			print f
			print e