Repository: sec-edgar/sec-edgar

Issue:
DailyFilings not working
Using the DailyFilings function to get a day's filings does not work, Line 92 of daily.py has a problem with datetime.strftime.

TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'str'

When I changed datetime.datetime.strftime to formatted_date = self._date.strftime("%y%m%d"), network_client.py gives a client-side error.

Thanks!

Comments:

Patch:
diff --git a/docs/source/whatsnew/v0.1.7.rst b/docs/source/whatsnew/v0.1.7.rst
new file mode 100644
index 0000000..0826855
--- /dev/null
+++ b/docs/source/whatsnew/v0.1.7.rst
@@ -0,0 +1,12 @@
+v0.1.7
+------
+
+Highlights
+~~~~~~~~~~
+
+* Fixes `DailyFilings` bug to properly fetch daily filings.
+
+Contributors
+~~~~~~~~~~~~
+
+- jonzd
\ No newline at end of file
diff --git a/secedgar/__init__.py b/secedgar/__init__.py
index 2fb2513..124e462 100644
--- a/secedgar/__init__.py
+++ b/secedgar/__init__.py
@@ -1,1 +1,1 @@
-__version__ = '0.1.6'
+__version__ = '0.1.7'
diff --git a/secedgar/filings/daily.py b/secedgar/filings/daily.py
index efafbd4..b11d124 100644
--- a/secedgar/filings/daily.py
+++ b/secedgar/filings/daily.py
@@ -47,8 +47,13 @@ class DailyFilings(AbstractFiling):
 
     @property
     def path(self):
-        """str: Path added to client base."""
-        return "Archives/edgar/daily-index/{year}/QTR{num}".format(
+        """str: Path added to client base.
+
+        .. note::
+            The trailing slash at the end of the path is important.
+            Omitting will raise EDGARQueryError.
+        """
+        return "Archives/edgar/daily-index/{year}/QTR{num}/".format(
             year=self._date.year, num=self.quarter)
 
     @property
@@ -72,6 +77,22 @@ class DailyFilings(AbstractFiling):
             self._quarterly_directory = self.client.get_response(self.path, self.params, **kwargs)
         return self._quarterly_directory
 
+    def _get_idx_formatted_date(self):
+        """Format date for idx file.
+
+        EDGAR changed its master.idx file format twice. In 1995 QTR 1 and in 1998 QTR 2.
+        The format went from MMDDYY to YYMMDD to YYYYMMDD.
+
+        Returns:
+            date (str): Correctly formatted date for master.idx file.
+        """
+        if self._date.year < 1995:
+            return self._date.strftime("%m%d%y")
+        elif self._date < datetime.datetime(1998, 3, 31):
+            return self._date.strftime("%y%m%d")
+        else:
+            return self._date.strftime("%Y%m%d")
+
     def _get_master_idx_file(self, update_cache=False, **kwargs):
         """Get master file with all filings from given date.
 
@@ -81,19 +102,20 @@ class DailyFilings(AbstractFiling):
             kwargs: Keyword arguments to pass to `client.get_response`.
 
         Returns:
-            text (str): Idx file as string.
+            text (str): Idx file text.
 
         Raises:
             EDGARQueryError: If no file of the form master.<DATE>.idx
                 is found.
         """
         if self._master_idx_file is None or update_cache:
-            formatted_date = datetime.datetime.strftime("%y%m%d", self._date)
+            formatted_date = self._get_idx_formatted_date()
             formatted_file_name = "master.{date}.idx".format(date=formatted_date)
             if formatted_file_name in self._get_quarterly_directory().text:
                 master_idx_url = "{path}/master.{date}.idx".format(
                     path=self.path, date=formatted_date)
-                self._master_idx_file = self.client.get_response(master_idx_url, **kwargs).text
+                self._master_idx_file = self.client.get_response(
+                    master_idx_url, self.params, **kwargs).text
             else:
                 raise EDGARQueryError("""File master.{date}.idx not found.
                                      There may be no filings for this day.""".format(
diff --git a/secedgar/utils/cik_map.py b/secedgar/utils/cik_map.py
index 40822f5..03b6cd4 100644
--- a/secedgar/utils/cik_map.py
+++ b/secedgar/utils/cik_map.py
@@ -14,7 +14,7 @@ def get_cik_map(key="ticker"):
 
     Returns:
         Dictionary with either ticker or company name as keys, depending on
-            ``key`` argument, and corresponding CIK as values.
+        ``key`` argument, and corresponding CIK as values.
 
     .. versionadded:: 0.1.6
     """


Test patch:
diff --git a/secedgar/tests/client/test_network_client.py b/secedgar/tests/client/test_network_client.py
index ae4c5a0..ce6bd1d 100644
--- a/secedgar/tests/client/test_network_client.py
+++ b/secedgar/tests/client/test_network_client.py
@@ -8,7 +8,7 @@ from secedgar.tests.utils import datapath
 
 @pytest.fixture
 def client():
-    return NetworkClient()
+    return NetworkClient(pause=0.01)
 
 
 class MockNoCIKFoundBadResponse:
diff --git a/secedgar/tests/filings/test_daily.py b/secedgar/tests/filings/test_daily.py
index 13da078..05a9a85 100644
--- a/secedgar/tests/filings/test_daily.py
+++ b/secedgar/tests/filings/test_daily.py
@@ -113,14 +113,32 @@ class TestDaily:
     )
     def test_path_property(self, year, month, day, quarter):
         daily_filing = DailyFilings(datetime(year, month, day))
-        assert daily_filing.path == "Archives/edgar/daily-index/{year}/QTR{quarter}".format(
+        assert daily_filing.path == "Archives/edgar/daily-index/{year}/QTR{quarter}/".format(
             year=year, quarter=quarter)
 
     def test_no_params(self):
+        """Params should always be empty."""
         daily_filing = DailyFilings(datetime(2020, 1, 1))
-        # params should always be empty
         assert not daily_filing.params
 
+    @pytest.mark.parametrize(
+        "date_tuple,formatted",
+        [
+            ((1994, 1, 2), "010294"),
+            ((1994, 12, 31), "123194"),
+            ((1995, 1, 1), "950101"),
+            ((1995, 1, 2), "950102"),
+            ((1998, 1, 1), "980101"),
+            ((1998, 1, 2), "980102"),
+            ((1998, 3, 31), "19980331"),
+            ((1998, 4, 1), "19980401"),
+            ((1999, 1, 1), "19990101"),
+        ]
+    )
+    def test_master_idx_date_format(self, date_tuple, formatted):
+        daily_filing = DailyFilings(datetime(*date_tuple))
+        assert daily_filing._get_idx_formatted_date() == formatted
+
     @pytest.mark.parametrize(
         "subdir,file",
         [