def __init__(self, cik_lookup, filing_type, start_date=None, end_date=datetime.datetime.today(), client=None, **kwargs): self._start_date = start_date self._end_date = end_date self._accession_numbers = [] if not isinstance(filing_type, FilingType): raise FilingTypeError self._filing_type = filing_type # make CIKLookup object for users if not given if not isinstance(cik_lookup, CIKLookup): cik_lookup = CIKLookup(cik_lookup) self._cik_lookup = cik_lookup self._params = { 'action': 'getcompany', 'dateb': sanitize_date(self.end_date), 'output': 'xml', 'owner': 'include', 'start': 0, 'type': self.filing_type.value } if kwargs.get('count') is not None: self._params['count'] = kwargs.get('count') if start_date is not None: self._params['datea'] = sanitize_date(start_date) # Make default client NetworkClient and pass in kwargs self._client = client if client is not None else NetworkClient( **kwargs)
def params(self): """:obj:`dict`: Parameters to include in requests.""" if self.start_date: self._params["datea"] = sanitize_date(self.start_date) else: self._params.pop("datea", None) # if no start date, make sure it isn't in params if self.end_date: self._params["dateb"] = sanitize_date(self.end_date) else: self._params.pop("dateb", None) # if no end date, make sure it isn't in params self._params["ownership"] = self.ownership return self._params
def _fetch_report(self, company_code, cik, priorto, count, filing_type): """Fetch filings. Args: company_code (str): Code used to help find company filings. Often the company's ticker is used. cik (Union[str, int]): Central Index Key assigned by SEC. See https://www.sec.gov/edgar/searchedgar/cik.htm to search for a company's CIK. priorto (Union[str, datetime.datetime]): Most recent report to consider. Must be in form 'YYYYMMDD' or valid ``datetime.datetime`` object. filing_type (str): Choose from list of valid filing types. Includes '10-Q', '10-K', '8-K', '13-F', 'SD'. Returns: None """ priorto = sanitize_date(priorto) cik = self._check_cik(cik) self._make_directory(company_code, cik, priorto, filing_type) # generate the url to crawl base_url = "http://www.sec.gov/cgi-bin/browse-edgar" params = { 'action': 'getcompany', 'owner': 'exclude', 'output': 'xml', 'CIK': cik, 'type': filing_type, 'dateb': priorto, 'count': count } print("started {filing_type} {company_code}".format( filing_type=filing_type, company_code=company_code)) r = requests.get(base_url, params=params) if r.status_code == 200: data = r.text # get doc list data docs = self._create_document_list(data) try: self._save_in_directory(company_code, cik, priorto, filing_type, docs) except Exception as e: print(str(e)) # Need to use str for Python 2.5 else: raise EDGARQueryError(r.status_code) print("Successfully downloaded all the files")
def end_date(self, val): self._end_date = val self._params['dateb'] = sanitize_date(val)
def start_date(self, val): if val is not None: self._start_date = val self._params['datea'] = sanitize_date(val) else: self._start_date = None
def end_date(self, val): sanitize_date(val) # make sure end date is valid self._end_date = val
def start_date(self, val): sanitize_date(val) # make sure start date is valid self._start_date = val
def start_date(self, val): self._start_date = val self._params['datea'] = sanitize_date(val)
def test_good_formats_datetime(self, dt_date, expected): assert sanitize_date(dt_date) == expected
def test_good_formats_no_change(self, good_date): """Tests formats that should not change from what is given. """ assert sanitize_date(good_date) == good_date
def test_bad_date_formats(self, bad_date): with pytest.raises(TypeError): sanitize_date(bad_date)
def end_date(self, val): self._params["dateb"] = sanitize_date(val) self._end_date = val
def start_date(self, val): if val is not None: self._params["datea"] = sanitize_date(val) self._start_date = val else: self._start_date = None