Skip to content

Commit d7f357d

Browse files
Update getBookmarkByPathAndShow.py
1 parent 7e9f1fa commit d7f357d

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

Uses-Cases/Bookmarks/get/getBookmarkByPathAndShow.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,29 @@ def _init_api(self, credentials_file: Path):
3434
except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
3535
logging.error(f"Failed to load credentials: {e}")
3636

37-
def _ensure_api_initialized(self):
38-
"""Check if the API is initialized before making API calls."""
39-
if not self.pdf_api:
40-
logging.error("PDF API is not initialized. Operation aborted.")
41-
return False
42-
return True
43-
4437
def upload_document(self):
4538
"""Upload a PDF document to the Aspose Cloud server."""
46-
if not self._ensure_api_initialized():
47-
return
48-
49-
file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME
50-
try:
51-
self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path))
52-
logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.")
53-
except Exception as e:
54-
logging.error(f"Failed to upload file: {e}")
39+
if self.pdf_api:
40+
file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME
41+
try:
42+
self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path))
43+
logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.")
44+
except Exception as e:
45+
logging.error(f"Failed to upload file: {e}")
5546

5647
def get_bookmark(self):
5748
"""Get bookmark for a specific PDF document using bookmark path."""
58-
if not self._ensure_api_initialized():
59-
return
60-
61-
try:
62-
response : BookmarkResponse = self.pdf_api.get_bookmark( Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH)
63-
if response.code == 200:
64-
logging.info(f"Found bookmark => level: '{response.bookmark.level}' - action: '{response.bookmark.action}' - title: '{response.bookmark.title}'")
65-
else:
66-
logging.error(f"Failed to find bookmark for the document. Response code: {response.code}")
67-
except Exception as e:
68-
logging.error(f"Error while find bookmark: {e}")
49+
if self.pdf_api:
50+
try:
51+
response : BookmarkResponse = self.pdf_api.get_bookmark( Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH)
52+
if response.code == 200:
53+
logging.info(f"Found bookmark => level: '{response.bookmark.level}' - action: '{response.bookmark.action}' - title: '{response.bookmark.title}'")
54+
else:
55+
logging.error(f"Failed to find bookmark for the document. Response code: {response.code}")
56+
except Exception as e:
57+
logging.error(f"Error while find bookmark: {e}")
6958

7059
if __name__ == "__main__":
7160
pdf_bookmarks = PdfBookmarks()
7261
pdf_bookmarks.upload_document()
73-
pdf_bookmarks.get_bookmark()
62+
pdf_bookmarks.get_bookmark()

0 commit comments

Comments
 (0)