Retrieves the entries of the specified glossary and returns them as a dictionary. :param glossary: GlossaryInfo or ID of glossary to retrieve. :return: dictionary of glossary entries. :raises GlossaryNotFoundException: If no glossary with given ID is foun
(self, glossary: Union[str, GlossaryInfo])
| 1156 | return [GlossaryInfo.from_json(glossary) for glossary in glossaries] |
| 1157 | |
| 1158 | def get_glossary_entries(self, glossary: Union[str, GlossaryInfo]) -> dict: |
| 1159 | """Retrieves the entries of the specified glossary and returns them as |
| 1160 | a dictionary. |
| 1161 | |
| 1162 | :param glossary: GlossaryInfo or ID of glossary to retrieve. |
| 1163 | :return: dictionary of glossary entries. |
| 1164 | :raises GlossaryNotFoundException: If no glossary with given ID is |
| 1165 | found. |
| 1166 | :raises DeepLException: If the glossary could not be retrieved |
| 1167 | in the right format. |
| 1168 | """ |
| 1169 | if isinstance(glossary, GlossaryInfo): |
| 1170 | glossary_id = glossary.glossary_id |
| 1171 | else: |
| 1172 | glossary_id = glossary |
| 1173 | |
| 1174 | status, content, json = self._api_call( |
| 1175 | f"v2/glossaries/{glossary_id}/entries", |
| 1176 | method="GET", |
| 1177 | headers={"Accept": "text/tab-separated-values"}, |
| 1178 | ) |
| 1179 | self._raise_for_status(status, content, json, glossary=True) |
| 1180 | if not isinstance(content, str): |
| 1181 | raise DeepLException( |
| 1182 | "Could not get the glossary content as a string", |
| 1183 | http_status_code=status, |
| 1184 | ) |
| 1185 | return util.convert_tsv_to_dict(content) |
| 1186 | |
| 1187 | def delete_glossary(self, glossary: Union[str, GlossaryInfo]) -> None: |
| 1188 | """Deletes specified glossary. |