def test_sanitation(self): """Test dates that are infered through sanitation.""" edgar_obj = Edgar('WMT') try: assert_equal(edgar_obj.get_filing_date(date(2009,1,31)), date(2009,4,1)) except ValueError: assert_false(True, 'Unable to find filing date for period ending 2009-01-31.')
def __init__(self, symbol, file_like_object, types): """Constructs a YchartsProvider for the given symbol and file_like_object with downloaded CSV data. It is assumed the CSV data does not contain price data, just quarterly financial data. The types are a list of names for the columns in the CSV after the period column. """ FinancialProvider.__init__(self, symbol) self.types = types edgar = Edgar(symbol) rows = file_like_object.read().strip().split("\n")[1:] data = [] for row in rows: fields = [x.strip() for x in row.strip().split(",")] data.append(fields) for field in fields: if field == "": data = [] break self.storage = {} self.storage['__period_end_date'] = [] self.storage['__filing_date'] = [] for type in types: self.storage[type] = [] for row in data: self.storage['__period_end_date'].append(datetime.strptime(row[0], '%Y-%m-%d').date()) for i in range(0,len(types)): self.storage[types[i]].append(float(row[i + 1]) * 1e6) for row in data: period_end_date = datetime.strptime(row[0], '%Y-%m-%d').date() try: self.storage['__filing_date'].append(edgar.get_filing_date(period_end_date)) except ValueError: if period_end_date < edgar.period_end_dates[0]: self.storage['__filing_date'].append(edgar.filing_dates[0]) else: raise