|
5 | 5 |
|
6 | 6 | query_api_endpoint = "https://api.sec-api.io" |
7 | 7 | full_text_search_api_endpoint = "https://api.sec-api.io/full-text-search" |
8 | | -render_api_endpoint = "https://archive.sec-api.io" |
| 8 | +filing_download_api_endpoint = "https://archive.sec-api.io" |
| 9 | +pdf_generator_api_endpoint = "https://api.sec-api.io/filing-reader" |
9 | 10 | xbrl_api_endpoint = "https://api.sec-api.io/xbrl-to-json" |
10 | 11 | extractor_api_endpoint = "https://api.sec-api.io/extractor" |
11 | 12 | # |
@@ -102,7 +103,7 @@ class RenderApi: |
102 | 103 |
|
103 | 104 | def __init__(self, api_key, proxies=None): |
104 | 105 | self.api_key = api_key |
105 | | - self.api_endpoint = render_api_endpoint |
| 106 | + self.api_endpoint = filing_download_api_endpoint |
106 | 107 | self.proxies = proxies if proxies else {} |
107 | 108 |
|
108 | 109 | def get_filing(self, url, return_binary=False): |
@@ -146,6 +147,37 @@ def get_file(self, url, return_binary=False): |
146 | 147 | handle_api_error(response) |
147 | 148 |
|
148 | 149 |
|
| 150 | +class PdfGeneratorApi: |
| 151 | + """ |
| 152 | + Base class for PDF Generator API |
| 153 | + """ |
| 154 | + |
| 155 | + def __init__(self, api_key, proxies=None): |
| 156 | + self.api_key = api_key |
| 157 | + self.api_endpoint = pdf_generator_api_endpoint |
| 158 | + self.proxies = proxies if proxies else {} |
| 159 | + |
| 160 | + def get_pdf(self, url): |
| 161 | + response = {} |
| 162 | + file_url = re.sub(r"ix\?doc=/", "", url) |
| 163 | + _url = ( |
| 164 | + self.api_endpoint + "?type=pdf&url=" + file_url + "&token=" + self.api_key |
| 165 | + ) |
| 166 | + |
| 167 | + # use backoff strategy to handle "too many requests" error. |
| 168 | + for x in range(3): |
| 169 | + response = requests.get(_url, proxies=self.proxies) |
| 170 | + if response.status_code == 200: |
| 171 | + return response.content |
| 172 | + elif response.status_code == 429: |
| 173 | + # wait 500 * (x + 1) milliseconds and try again |
| 174 | + time.sleep(0.5 * (x + 1)) |
| 175 | + else: |
| 176 | + handle_api_error(response) |
| 177 | + else: |
| 178 | + handle_api_error(response) |
| 179 | + |
| 180 | + |
149 | 181 | class XbrlApi: |
150 | 182 | """ |
151 | 183 | Base class for XBRL-to-JSON API |
|
0 commit comments