def load_stock_history_quotation(self, stock_codes):
#????????
for stock_code in stock_codes:
self._create_stock_quotation_table(stock_code)
history_files = []
for root, _, files in os.walk('./stock_history/'):
for f in files:
if f.startswith(u'????'):
history_files.append(root + f)
#??????,????????
history_files.reverse()
for history_file in history_files:
excel = xlrd.open_workbook(history_file)
#???????
sheet = excel.sheets()[0]
# codes_line = sheet.row_values(2)
#??????,??????????,??????,?????
quotations = dict()
for col in range(1, sheet.ncols, 2):
code = sheet.cell(1, col).value.split('.')[0]
#????????choice?code???
ss = []
if code in stock_codes:
#???????????????????1?,2????,3???,???????????,?????,??????,???
#?????,????????,???????,?????date???,????????
for row in range(sheet.nrows-3, 3, -1):
#??????,?????
date_data = sheet.cell(row, 0).value
if isinstance(date_data, basestring) and len(date_data) == 0:
break
pb = sheet.cell(row, col).value
pe = sheet.cell(row, col+1).value
#pb,pe???,??????,?????????,?????????,?????,??????
#?????????,???????????????,?????,???????output??
if (isinstance(pb, basestring) and len(pb) == 0) or (isinstance(pe, basestring) and len(pe) == 0):
break
else:
date_tuple = xlrd.xldate_as_tuple(date_data, 0)
date = '{}-{:0>2}-{:0>2}'.format(date_tuple[0], date_tuple[1], date_tuple[2])
ss.append((date, safe_to_float(pe), safe_to_float(pb)))
else:
print 'code ' + code + " not in eastmoney"
if len(ss) > 0:
quotations[code] = ss
self._batch_update_stock_history_quotation(quotations)
print 'load history file finish ' + history_file
#??????
评论列表
文章目录