From 4571fc6a82f4190896bc7fe952cb747bba4aa8a1 Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Sun, 14 Jun 2026 02:33:50 -0700 Subject: fix: clean up get_sec_filings (cache decorator, url shadowing, dead code, imports) --- backend/app/services/data_service.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'backend/app/services/data_service.py') diff --git a/backend/app/services/data_service.py b/backend/app/services/data_service.py index e9f3dab..caa8294 100644 --- a/backend/app/services/data_service.py +++ b/backend/app/services/data_service.py @@ -1,9 +1,11 @@ """yfinance wrapper for Prism v2 Overview data.""" from __future__ import annotations +import datetime import math import os import statistics +from collections import defaultdict from typing import Any import httpx @@ -1881,10 +1883,7 @@ _FORM_DESCRIPTIONS: dict[str, str] = { "SC 13D": "Beneficial ownership (active)", } -_PRIMARY_FORMS = {"10-K", "10-Q", "8-K"} - - -@cached(cache=FILINGS_CACHE) +@cached(FILINGS_CACHE) def get_sec_filings(symbol: str) -> dict: """Fetch and pre-process SEC filings for a ticker. @@ -1892,9 +1891,6 @@ def get_sec_filings(symbol: str) -> dict: Data source: yfinance `sec_filings`. FMP fallback if FMP_API_KEY is set and yfinance returns empty. """ - import datetime - from collections import defaultdict - sym = normalize_symbol(symbol) raw: list[dict] = [] @@ -1928,7 +1924,7 @@ def get_sec_filings(symbol: str) -> dict: title = str(r.get("title") or _FORM_DESCRIPTIONS.get(form, form)).strip() # URL: prefer primary form exhibit, fall back to edgarUrl/link exhibits = r.get("exhibits") or {} - url = exhibits.get(form) or r.get("edgarUrl") or r.get("link") or None + filing_url = exhibits.get(form) or r.get("edgarUrl") or r.get("link") or None if not date_raw or not form: continue @@ -1944,7 +1940,7 @@ def get_sec_filings(symbol: str) -> dict: except (ValueError, TypeError): continue - items.append({"date": date_str, "form": form, "title": title, "url": url}) + items.append({"date": date_str, "form": form, "title": title, "url": filing_url}) # Sort descending by date items.sort(key=lambda x: x["date"], reverse=True) -- cgit v1.3-2-g0d8e