-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
652 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SECAPIO_API_KEY=your-api-key-here |
This file was deleted.
Oops, something went wrong.
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 +1 @@ | ||
__version__ = "0.0.1" | ||
__version__ = "0.0.2" |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import TYPE_CHECKING | ||
|
||
from sec_api_io.sec_edgar_enums import DocumentType, SectionType | ||
from sec_api_io.sec_edgar_utils import validate_sections | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Iterable | ||
|
||
|
||
class DocumentTypeNotSupportedError(ValueError): | ||
pass | ||
|
||
|
||
class AbstractSECDataRetriever(ABC): | ||
SUPPORTED_DOCUMENT_TYPES: frozenset[DocumentType] = frozenset() | ||
|
||
def __init__(self) -> None: | ||
if self.SUPPORTED_DOCUMENT_TYPES is None: | ||
msg = "SUPPORTED_DOCUMENT_TYPES must be set in subclass" | ||
raise NotImplementedError( # pragma: no cover | ||
msg, | ||
) | ||
|
||
def get_report_html( | ||
self: AbstractSECDataRetriever, | ||
doc_type: DocumentType | str, | ||
url: str, | ||
*, | ||
sections: Iterable[SectionType | str] | None = None, | ||
) -> str: | ||
doc_type, sections = self._validate_and_convert(doc_type, sections) | ||
|
||
# Using the Template Method Pattern here to ensure all necessary | ||
# validations are performed before calling the actual implementation. | ||
# Subclasses are expected to implement _get_html_from_url for the | ||
# core functionality. | ||
return self._get_report_html( | ||
doc_type, | ||
url=url, | ||
sections=sections, | ||
) | ||
|
||
@abstractmethod | ||
def _get_report_html( | ||
self: AbstractSECDataRetriever, | ||
doc_type: DocumentType, | ||
url: str, | ||
*, | ||
sections: Iterable[SectionType] | None = None, | ||
) -> str: | ||
raise NotImplementedError # pragma: no cover | ||
|
||
def _validate_and_convert( | ||
self, | ||
doc_type: DocumentType | str, | ||
sections: Iterable[SectionType | str] | None = None, | ||
) -> tuple[DocumentType, Iterable[SectionType] | None]: | ||
new_doc_type = ( | ||
DocumentType.from_str(doc_type) if isinstance(doc_type, str) else doc_type | ||
) | ||
if new_doc_type not in self.SUPPORTED_DOCUMENT_TYPES: | ||
msg = f"Document type {doc_type} not supported." | ||
raise DocumentTypeNotSupportedError(msg) | ||
new_sections = ( | ||
[ | ||
SectionType.from_str(section) if isinstance(section, str) else section | ||
for section in sections | ||
] | ||
if sections | ||
else None | ||
) | ||
validate_sections(new_doc_type, new_sections) | ||
return new_doc_type, new_sections |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.