Fix hedge fund 13F HTML wrapper, field names; fix cache builder rate limiting
This commit is contained in:
parent
c115eee74a
commit
0cad4df12d
|
|
@ -2465,6 +2465,14 @@ def _parse_13f_xml(xml_bytes: bytes) -> list[dict]:
|
||||||
company, class_, cusip, value (USD), shares, shr_type, put_call
|
company, class_, cusip, value (USD), shares, shr_type, put_call
|
||||||
"""
|
"""
|
||||||
import xml.etree.ElementTree as ET
|
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 <informationTable> block.
|
||||||
|
if xml_bytes[:500].upper().find(b'<!DOCTYPE HTML') != -1:
|
||||||
|
m = _re.search(rb'(<informationTable[\s\S]*?</informationTable>)',
|
||||||
|
xml_bytes, _re.IGNORECASE)
|
||||||
|
if m:
|
||||||
|
xml_bytes = m.group(1)
|
||||||
try:
|
try:
|
||||||
root = ET.fromstring(xml_bytes)
|
root = ET.fromstring(xml_bytes)
|
||||||
except ET.ParseError:
|
except ET.ParseError:
|
||||||
|
|
@ -2607,9 +2615,10 @@ def fetch_hedge_fund_filings(
|
||||||
src = hit.get("_source", {})
|
src = hit.get("_source", {})
|
||||||
acc_no = src.get("adsh", "")
|
acc_no = src.get("adsh", "")
|
||||||
ciks = src.get("ciks", [])
|
ciks = src.get("ciks", [])
|
||||||
fund_name = src.get("entity_name", "Unknown Fund")
|
display = src.get("display_names") or src.get("entity_name") or []
|
||||||
filed = (src.get("file_date") or "")[:10]
|
fund_name = display[0].split(" (CIK")[0].strip() if display else "Unknown Fund"
|
||||||
period = (src.get("period_of_report") or "")[:10]
|
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:
|
if not acc_no or not ciks:
|
||||||
return []
|
return []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue