def setUp(self): datadir="D:\Personal\Finnance\Stock\Flow" tmpfile = "tmp/dump" flow = parse_tdx_flow(os.path.join(datadir, 'flow201405.xls')) #pprint(flow) self.data = flow self.dumpfile = tmpfile
def setUp(self): datadir = "D:\Personal\Finnance\Stock\Flow" tmpfile = "tmp/dump" flow = parse_tdx_flow(os.path.join(datadir, 'flow201405.xls')) #pprint(flow) self.data = flow self.dumpfile = tmpfile
def dump_flow(month_start, month_end, outfile, datadir=datadir): """Dump tdx_flow files to pickle""" str2date = lambda x: datetime.datetime.strptime(x, '%Y%m') date2str = lambda x: datetime.datetime.strftime(x, '%Y%m') one_month = dateutil.relativedelta.relativedelta(months=1) start, end = str2date(month_start), str2date(month_end) if start > end: raise ValueError("start month should be less than end month") recs = [] current = start while current <= end: file = os.path.join(datadir, 'flow'+date2str(current)+".xls") recs.extend(parse_tdx_flow(file)) current += one_month with open(outfile, 'wb') as fh: pickle.dump(recs, fh)