-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev_utils): remove sec-api.io integration from Debug Dashboard
- Loading branch information
Showing
6 changed files
with
181 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,30 @@ | ||
from typing import Optional | ||
from pathlib import Path | ||
|
||
import streamlit as st | ||
from sec_downloader import DownloadStorage | ||
from sec_edgar_downloader import Downloader | ||
|
||
import sec_parser as sp | ||
from dev_utils.debug_dashboard.cache_utils import cache_to_file | ||
|
||
|
||
@st.cache_data( | ||
experimental_allow_widgets=True, | ||
show_spinner="Retrieving SEC EDGAR document...", | ||
) | ||
@cache_to_file( | ||
cache_by_keys={"latest_from_ticker", "doc", "url", "sections"}, | ||
cache_dir=".cache/metadata", | ||
) | ||
def get_metadata( | ||
_secapi_api_key: str, # prefix _ prevents hashing in st.cache_data | ||
*, | ||
doc: sp.DocumentType | str, | ||
url: str | None = None, | ||
latest_from_ticker: str | None = None, | ||
) -> str: | ||
from sec_edgar_downloader import Downloader | ||
retriever = sp.SecapioDataRetriever(api_key=_secapi_api_key) | ||
return retriever.retrieve_report_metadata( | ||
doc, | ||
url=url, | ||
latest_from_ticker=latest_from_ticker, | ||
) | ||
EDGAR_CLIENT_NAME = "Alphanome.AI" | ||
EDGAR_CLIENT_EMAIL = "[email protected]" | ||
|
||
|
||
@st.cache_data( | ||
experimental_allow_widgets=True, | ||
show_spinner="Retrieving SEC EDGAR document...", | ||
) | ||
@cache_to_file( | ||
cache_by_keys={"url", "ticker", "doc", "sections"}, | ||
cache_dir=".cache/html", | ||
) | ||
def download_html( | ||
_secapi_api_key: str, # prefix _ prevents hashing in st.cache_data | ||
def get_latest_10q_html( | ||
*, | ||
ticker: str, # added just to make the cache write ticker as part of the filename | ||
doc: sp.DocumentType | str, | ||
url: str, | ||
sections: Optional[list[sp.SectionType | str]] = None, | ||
ticker: str, | ||
) -> str: | ||
retriever = sp.SecapioDataRetriever(api_key=_secapi_api_key) | ||
return retriever.get_report_html(doc, url, sections=sections) | ||
ticker = ticker.upper().strip() | ||
assert ticker, "Ticker must not be empty" | ||
storage = DownloadStorage(filter_pattern="**/*.htm*") | ||
with storage as path: | ||
dl = Downloader(EDGAR_CLIENT_NAME, EDGAR_CLIENT_EMAIL, path) | ||
dl.get("10-Q", ticker, limit=1, download_details=True) | ||
return storage.get_file_contents()[0].content | ||
|
||
|
||
@st.cache_resource | ||
|
Oops, something went wrong.