FuncPhenomenon commited on
Commit
e4c3821
·
verified ·
1 Parent(s): ae7a494

created tool to get latest SEC filing info

Browse files
Files changed (1) hide show
  1. app.py +87 -8
app.py CHANGED
@@ -4,19 +4,98 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
  from Gradio_UI import GradioUI
 
 
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
+ from xml.etree import ElementTree
9
+ from typing import Union, List, Dict, Any
10
 
 
11
  @tool
12
+ def get_lastest_filing_info(company: str = None, cik: str = None, type: str = "10-K", dateb: str = None, start: str = '0', count: str = '50') -> Union[List[Dict[str, Any]], Dict[str, str]]:
13
+ """A tool that gets the most recent 10-K filings (including addendums) of a company from the SEC.
 
14
  Args:
15
+ company: The name of the company.
16
+ cik: The Central Index Key (CIK) of the company.
17
+ type: The type of filing. (Default is "10-K" for this function.)
18
+ dateb: The date before which the filings were made (format: YYYYMMDD).
19
+ start: The starting point for pagination.
20
+ count: The number of filings to retrieve per page.
21
+ Returns:
22
+ The latest filings of a company from the SEC.
23
  """
24
+ # Validate dateb format
25
+ if dateb:
26
+ try:
27
+ datetime.datetime.strptime(dateb, "%Y%m%d")
28
+ except ValueError:
29
+ return {"error": "Invalid dateb format. Use YYYYMMDD."}
30
+
31
+ # Ensure dateb is not after the current time
32
+ current_date = datetime.datetime.now().strftime("%Y%m%d")
33
+ if dateb and dateb > current_date:
34
+ return {"error": "dateb cannot be after the current date."}
35
+
36
+ base_url = "https://www.sec.gov/cgi-bin/browse-edgar?action=getcurrent"
37
+ params = {
38
+ "CIK": cik,
39
+ "type": type,
40
+ "company": company,
41
+ "dateb": dateb,
42
+ "owner": "include",
43
+ "start": start,
44
+ "count": count,
45
+ "output": "atom"
46
+ }
47
+
48
+ response = requests.get(base_url, params=params)
49
+ if response.status_code != 200:
50
+ return {"error": "Failed to retrieve data from SEC"}
51
+
52
+ filings = []
53
+ try:
54
+ feed = response.content
55
+ root = ElementTree.fromstring(feed)
56
+ # Process filings from the first page
57
+ for entry in root.findall("{http://www.w3.org/2005/Atom}entry"):
58
+ filing = {
59
+ "title": entry.find("{http://www.w3.org/2005/Atom}title").text,
60
+ "link": entry.find("{http://www.w3.org/2005/Atom}link").attrib['href'],
61
+ "summary": entry.find("{http://www.w3.org/2005/Atom}summary").text,
62
+ "updated": entry.find("{http://www.w3.org/2005/Atom}updated").text,
63
+ "category": entry.find("{http://www.w3.org/2005/Atom}category").attrib['term'],
64
+ "id": entry.find("{http://www.w3.org/2005/Atom}id").text
65
+ }
66
+ # Only include filings where category starts with "10-K"
67
+ if filing["category"].startswith("10-K"):
68
+ filings.append(filing)
69
+
70
+ # Fetch additional pages until we have 100 filings or no more are available
71
+ while len(filings) < 100:
72
+ params["start"] = str(int(params["start"]) + int(params["count"]))
73
+ response = requests.get(base_url, params=params)
74
+ if response.status_code != 200:
75
+ break
76
+ feed = response.content
77
+ root = ElementTree.fromstring(feed)
78
+ entries = root.findall("{http://www.w3.org/2005/Atom}entry")
79
+ if not entries:
80
+ break
81
+ for entry in entries:
82
+ filing = {
83
+ "title": entry.find("{http://www.w3.org/2005/Atom}title").text,
84
+ "link": entry.find("{http://www.w3.org/2005/Atom}link").attrib['href'],
85
+ "summary": entry.find("{http://www.w3.org/2005/Atom}summary").text,
86
+ "updated": entry.find("{http://www.w3.org/2005/Atom}updated").text,
87
+ "category": entry.find("{http://www.w3.org/2005/Atom}category").attrib['term'],
88
+ "id": entry.find("{http://www.w3.org/2005/Atom}id").text
89
+ }
90
+ if filing["category"].startswith("10-K"):
91
+ filings.append(filing)
92
+ if len(filings) >= 100:
93
+ break
94
+
95
+ except Exception as e:
96
+ return {"error": f"Failed to parse XML: {str(e)}"}
97
+
98
+ return filings
99
 
100
  @tool
101
  def get_current_time_in_timezone(timezone: str) -> str: