diff --git a/dist/stock_screener.py b/dist/stock_screener.py index c036f44..b616039 100644 --- a/dist/stock_screener.py +++ b/dist/stock_screener.py @@ -2465,6 +2465,14 @@ def _parse_13f_xml(xml_bytes: bytes) -> list[dict]: company, class_, cusip, value (USD), shares, shr_type, put_call """ import xml.etree.ElementTree as ET + import re as _re + # SEC serves 13F XML wrapped in an HTML document (Content-Type: text/html). + # Strip the HTML wrapper and extract just the block. + if xml_bytes[:500].upper().find(b')', + xml_bytes, _re.IGNORECASE) + if m: + xml_bytes = m.group(1) try: root = ET.fromstring(xml_bytes) except ET.ParseError: @@ -2607,9 +2615,10 @@ def fetch_hedge_fund_filings( src = hit.get("_source", {}) acc_no = src.get("adsh", "") ciks = src.get("ciks", []) - fund_name = src.get("entity_name", "Unknown Fund") - filed = (src.get("file_date") or "")[:10] - period = (src.get("period_of_report") or "")[:10] + display = src.get("display_names") or src.get("entity_name") or [] + fund_name = display[0].split(" (CIK")[0].strip() if display else "Unknown Fund" + filed = (src.get("file_date") or "")[:10] + period = (src.get("period_ending") or src.get("period_of_report") or "")[:10] if not acc_no or not ciks: return []