-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_company.py
More file actions
64 lines (50 loc) · 2.02 KB
/
find_company.py
File metadata and controls
64 lines (50 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Example: Search for a Company and View its Profile
Demonstrates searching for companies by name or ticker, then fetching the
full company profile including recent SEC filings.
Get your free API key:
https://rapidapi.com/dapdev-dapdev-default/api/sec-edgar-financial-data-api
"""
import os
import sys
from edgar_client import EdgarAPI
API_KEY = os.environ.get("RAPIDAPI_KEY", "YOUR_API_KEY_HERE")
def main():
query = sys.argv[1] if len(sys.argv) > 1 else "Apple"
with EdgarAPI(api_key=API_KEY) as api:
# --- Search ---
print(f'Searching for "{query}"...\n')
results = api.search_companies(query, limit=5)
if not results:
print("No companies found.")
return
print(f"{'CIK':<12} {'Ticker':<8} {'Name'}")
print("-" * 50)
for c in results:
print(f"{c.cik:<12} {c.ticker:<8} {c.name}")
# --- Profile for the first result ---
first = results[0]
print(f"\nFetching profile for {first.name} (CIK {first.cik})...\n")
profile = api.company(first.cik)
sep = "=" * 60
print(sep)
print(" " + profile.get("name", "N/A"))
print(" Ticker : " + profile.get("ticker", "N/A"))
print(" SIC : " + str(profile.get("sic", "N/A")))
print(" Industry : " + profile.get("sic_description", "N/A"))
print(" State : " + profile.get("state_of_inc", "N/A"))
print(" Fiscal Year : " + profile.get("fiscal_year_end", "N/A"))
print(sep)
# --- Recent filings ---
filings = profile.get("recent_filings", [])[:10]
if filings:
print("\nRecent Filings:")
print(f" {'Form':<12} {'Filed':<14} {'Description'}")
print(" " + "-" * 55)
for f in filings:
form = f.get("form", "")
filed = f.get("filed", "")
desc = f.get("description", "")[:40]
print(f" {form:<12} {filed:<14} {desc}")
if __name__ == "__main__":
main()