Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -94,16 +94,42 @@ def extract_financial_metrics(cik: str, years: int = 3) -> dict:
|
|
| 94 |
if years < 1 or years > 10:
|
| 95 |
return {"error": "Years parameter must be between 1 and 10"}
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
return {
|
| 102 |
-
"
|
| 103 |
-
"
|
|
|
|
| 104 |
}
|
| 105 |
-
else:
|
| 106 |
-
return {"error": f"No financial metrics extracted for CIK: {cik}"}
|
| 107 |
|
| 108 |
|
| 109 |
@mcp.tool()
|
|
|
|
| 94 |
if years < 1 or years > 10:
|
| 95 |
return {"error": "Years parameter must be between 1 and 10"}
|
| 96 |
|
| 97 |
+
try:
|
| 98 |
+
metrics = financial_analyzer.extract_financial_metrics(cik, years)
|
| 99 |
+
|
| 100 |
+
if metrics:
|
| 101 |
+
formatted = financial_analyzer.format_financial_data(metrics)
|
| 102 |
+
return {
|
| 103 |
+
"periods": len(formatted),
|
| 104 |
+
"data": formatted
|
| 105 |
+
}
|
| 106 |
+
else:
|
| 107 |
+
# Return helpful debug info
|
| 108 |
+
filings_10k = edgar_client.get_company_filings(cik, ('10-K',))
|
| 109 |
+
filings_20f = edgar_client.get_company_filings(cik, ('20-F',))
|
| 110 |
+
|
| 111 |
+
return {
|
| 112 |
+
"error": f"No financial metrics extracted for CIK: {cik}",
|
| 113 |
+
"debug": {
|
| 114 |
+
"cik": cik,
|
| 115 |
+
"years_requested": years,
|
| 116 |
+
"filings_found": {
|
| 117 |
+
"10-K": len(filings_10k),
|
| 118 |
+
"20-F": len(filings_20f)
|
| 119 |
+
},
|
| 120 |
+
"latest_filings": [
|
| 121 |
+
{"form": f.get("form_type"), "date": f.get("filing_date")}
|
| 122 |
+
for f in (filings_10k + filings_20f)[:5]
|
| 123 |
+
]
|
| 124 |
+
},
|
| 125 |
+
"suggestion": "Try using get_latest_financial_data or get_financial_data with a specific period"
|
| 126 |
+
}
|
| 127 |
+
except Exception as e:
|
| 128 |
return {
|
| 129 |
+
"error": f"Exception extracting metrics: {str(e)}",
|
| 130 |
+
"cik": cik,
|
| 131 |
+
"years": years
|
| 132 |
}
|
|
|
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
@mcp.tool()
|