@@ -128,11 +128,13 @@ def _retrieve_document_content(self, document_content: dict) -> str:
128128 else :
129129 raise Exception (f"The notice content can't be loaded!: { response } , { response .content } " )
130130
131- def get_generator_by_query (self , query : dict , result_fields : dict = None ) -> Generator [dict , None , None ]:
131+ def get_generator_by_query (self , query : dict , result_fields : dict = None , load_content : bool = True ) -> Generator [
132+ dict , None , None ]:
132133 """
133134 Method to get a documents content by passing a query to the API (json)
134135 :param query:
135136 :param result_fields:
137+ :param load_content:
136138 :return:Generator[dict]
137139 """
138140 query .update (DEFAULT_TED_API_QUERY_RESULT_SIZE )
@@ -146,30 +148,28 @@ def get_generator_by_query(self, query: dict, result_fields: dict = None) -> Gen
146148 query [RESULT_PAGE_NUMBER ] = page_number
147149 response_body = self .request_api (api_url = self .ted_api_url , api_query = query )
148150 documents_content += response_body [RESPONSE_RESULTS ]
149- for document_content in documents_content :
151+
152+ for document_content in documents_content :
153+ if load_content :
150154 document_content [DOCUMENT_CONTENT ] = self ._retrieve_document_content (document_content )
151- # document_id = document_content[DOCUMENT_NOTICE_ID_KEY]
152- # document_id = "0" * (11 - len(document_id)) + document_id
153- # document_content[DOCUMENT_NOTICE_ID_KEY] = document_id
154155 del document_content [LINKS_TO_CONTENT_KEY ]
155- yield document_content
156+ yield document_content
156157 else :
157158 for document_content in documents_content :
158- document_content [DOCUMENT_CONTENT ] = self ._retrieve_document_content (document_content )
159- # document_id = document_content[DOCUMENT_NOTICE_ID_KEY]
160- # document_id = "0" * (11 - len(document_id)) + document_id
161- # document_content[DOCUMENT_NOTICE_ID_KEY] = document_id
162- del document_content [LINKS_TO_CONTENT_KEY ]
159+ if load_content :
160+ document_content [DOCUMENT_CONTENT ] = self ._retrieve_document_content (document_content )
161+ del document_content [LINKS_TO_CONTENT_KEY ]
163162 yield document_content
164163
165- def get_by_query (self , query : dict , result_fields : dict = None ) -> List [dict ]:
164+ def get_by_query (self , query : dict , result_fields : dict = None , load_content : bool = True ) -> List [dict ]:
166165 """
167166 Method to get a documents content by passing a query to the API (json)
168167 :param query:
169168 :param result_fields:
169+ :param load_content:
170170 :return:List[dict]
171171 """
172- return list (self .get_generator_by_query (query = query , result_fields = result_fields ))
172+ return list (self .get_generator_by_query (query = query , result_fields = result_fields , load_content = load_content ))
173173
174174 def get_by_id (self , document_id : str ) -> dict :
175175 """
0 commit comments