@@ -65,8 +65,14 @@ def get_recent_filings(
6565 except Exception as e :
6666 return {"success" : False , "error" : f"Failed to get recent filings: { str (e )} " }
6767
68- def get_filing_content (self , identifier : str , accession_number : str ) -> ToolResponse :
69- """Get the content of a specific filing."""
68+ def get_filing_content (
69+ self ,
70+ identifier : str ,
71+ accession_number : str ,
72+ offset : int = 0 ,
73+ max_chars : int = 50000 ,
74+ ) -> ToolResponse :
75+ """Get filing content with paging support."""
7076 try :
7177 company = self .client .get_company (identifier )
7278
@@ -80,34 +86,32 @@ def get_filing_content(self, identifier: str, accession_number: str) -> ToolResp
8086 if not filing :
8187 raise FilingNotFoundError (f"Filing { accession_number } not found" )
8288
83- # Get filing content
8489 content = filing .text ()
90+ total_chars = len (content )
91+
92+ safe_offset = max (0 , int (offset ))
93+ safe_max_chars = int (max_chars ) if max_chars and int (max_chars ) > 0 else 50000
94+
95+ page_end = min (safe_offset + safe_max_chars , total_chars )
96+ if safe_offset >= total_chars :
97+ page_content = ""
98+ page_end = total_chars
99+ else :
100+ page_content = content [safe_offset :page_end ]
85101
86- # For structured filings, get the data object
87- filing_data = {}
88- try :
89- obj = filing .obj ()
90- if obj :
91- # Extract key information based on filing type
92- if filing .form == "8-K" and hasattr (obj , "items" ):
93- filing_data ["items" ] = obj .items
94- filing_data ["has_press_release" ] = getattr (obj , "has_press_release" , False )
95- elif filing .form in ["10-K" , "10-Q" ]:
96- filing_data ["has_financials" ] = True
97- elif filing .form in ["3" , "4" , "5" ]:
98- filing_data ["is_ownership" ] = True
99- except Exception :
100- pass
102+ next_offset = page_end if page_end < total_chars else None
101103
102104 return {
103105 "success" : True ,
104106 "accession_number" : filing .accession_number ,
105107 "form_type" : filing .form ,
106108 "filing_date" : filing .filing_date .isoformat (),
107- "content" : content [:50000 ] if len (content ) > 50000 else content , # Limit size
108- "content_truncated" : len (content ) > 50000 ,
109- "filing_data" : filing_data ,
109+ "content" : page_content ,
110110 "url" : filing .url ,
111+ "offset" : safe_offset ,
112+ "returned_chars" : len (page_content ),
113+ "total_chars" : total_chars ,
114+ "next_offset" : next_offset ,
111115 }
112116 except FilingNotFoundError as e :
113117 return {"success" : False , "error" : str (e )}
0 commit comments