Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from xml.etree import ElementTree
|
|
9 |
|
10 |
@tool
|
11 |
def get_lastest_filing_info(company: str = None, cik: str = None, type: str = "10-K", dateb: str = None, start: str = '0', count: str = '50') -> str:
|
12 |
-
"""A tool that gets the most recent 10-K filings of a company from the SEC.
|
13 |
Args:
|
14 |
company: The name of the company.
|
15 |
cik: The Central Index Key (CIK) of the company.
|
@@ -24,8 +24,9 @@ def get_lastest_filing_info(company: str = None, cik: str = None, type: str = "1
|
|
24 |
if dateb:
|
25 |
try:
|
26 |
datetime.datetime.strptime(dateb, "%Y%m%d")
|
27 |
-
except ValueError:
|
28 |
-
|
|
|
29 |
|
30 |
# Ensure dateb is not after the current time
|
31 |
current_date = datetime.datetime.now().strftime("%Y%m%d")
|
@@ -43,10 +44,15 @@ def get_lastest_filing_info(company: str = None, cik: str = None, type: str = "1
|
|
43 |
"count": count,
|
44 |
"output": "atom"
|
45 |
}
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
response = requests.get(base_url, params=params)
|
48 |
if response.status_code != 200:
|
49 |
-
|
|
|
50 |
|
51 |
filings = []
|
52 |
try:
|
@@ -69,8 +75,9 @@ def get_lastest_filing_info(company: str = None, cik: str = None, type: str = "1
|
|
69 |
# Fetch additional pages until we have 100 filings or no more are available
|
70 |
while len(filings) < 100:
|
71 |
params["start"] = str(int(params["start"]) + int(params["count"]))
|
72 |
-
response = requests.get(base_url, params=params)
|
73 |
if response.status_code != 200:
|
|
|
74 |
break
|
75 |
feed = response.content
|
76 |
root = ElementTree.fromstring(feed)
|
|
|
9 |
|
10 |
@tool
|
11 |
def get_lastest_filing_info(company: str = None, cik: str = None, type: str = "10-K", dateb: str = None, start: str = '0', count: str = '50') -> str:
|
12 |
+
"""A tool that gets the most recent 10-K filings (including addendums) of a company from the SEC.
|
13 |
Args:
|
14 |
company: The name of the company.
|
15 |
cik: The Central Index Key (CIK) of the company.
|
|
|
24 |
if dateb:
|
25 |
try:
|
26 |
datetime.datetime.strptime(dateb, "%Y%m%d")
|
27 |
+
except ValueError as e:
|
28 |
+
print(f"Date validation error: {e}")
|
29 |
+
return {"error": str(e)}
|
30 |
|
31 |
# Ensure dateb is not after the current time
|
32 |
current_date = datetime.datetime.now().strftime("%Y%m%d")
|
|
|
44 |
"count": count,
|
45 |
"output": "atom"
|
46 |
}
|
47 |
+
# Set a proper User-Agent header per SEC guidelines
|
48 |
+
headers = {
|
49 |
+
"User-Agent": "FuncPhenomenon SMOLAgentTest/1.0"
|
50 |
+
}
|
51 |
|
52 |
+
response = requests.get(base_url, params=params, headers=headers)
|
53 |
if response.status_code != 200:
|
54 |
+
print(f"SEC retrieval error: {response.text}")
|
55 |
+
return {"error": response.text}
|
56 |
|
57 |
filings = []
|
58 |
try:
|
|
|
75 |
# Fetch additional pages until we have 100 filings or no more are available
|
76 |
while len(filings) < 100:
|
77 |
params["start"] = str(int(params["start"]) + int(params["count"]))
|
78 |
+
response = requests.get(base_url, params=params, headers=headers)
|
79 |
if response.status_code != 200:
|
80 |
+
print(f"SEC retrieval error on pagination: {response.text}")
|
81 |
break
|
82 |
feed = response.content
|
83 |
root = ElementTree.fromstring(feed)
|