Skip to content

Commit 6e6eee3

Browse files
Update removeBookmark.py
1 parent 0ed660f commit 6e6eee3

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

Uses-Cases/Bookmarks/remove/removeBookmark.py

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,35 @@ def _init_api(self, credentials_file: Path):
3636
except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
3737
logging.error(f"Failed to load credentials: {e}")
3838

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

5849
def download_result(self):
5950
"""Download the processed PDF document from the Aspose Cloud server."""
60-
if not self._ensure_api_initialized():
61-
return
62-
63-
try:
64-
temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME)
65-
local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME
66-
shutil.move(temp_file, str(local_path))
67-
logging.info(f"download_result(): File successfully downloaded: {local_path}")
68-
except Exception as e:
69-
logging.error(f"download_result(): Failed to download file: {e}")
51+
if self.pdf_api:
52+
try:
53+
temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME)
54+
local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME
55+
shutil.move(temp_file, str(local_path))
56+
logging.info(f"download_result(): File successfully downloaded: {local_path}")
57+
except Exception as e:
58+
logging.error(f"download_result(): Failed to download file: {e}")
7059

7160
def remove_bookmark_by_path(self):
72-
if not self.pdf_api:
73-
return
74-
75-
response: AsposeResponse = self.pdf_api.delete_bookmark(Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH)
61+
if self.pdf_api:
62+
response: AsposeResponse = self.pdf_api.delete_bookmark(Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH)
7663

77-
if response.code == 200:
78-
logging.info(f"Bookmark with path: '{Config.BOOKMARK_PATH}' has been removed.")
79-
else:
80-
logging.erro(f"Failed to remove bookmark with path: '{Config.LINK_FIND_ID}'.")
64+
if response.code == 200:
65+
logging.info(f"Bookmark with path: '{Config.BOOKMARK_PATH}' has been removed.")
66+
else:
67+
logging.erro(f"Failed to remove bookmark with path: '{Config.LINK_FIND_ID}")
8168

8269
if __name__ == "__main__":
8370
pdf_bookmarks = PdfBookmarks()

0 commit comments

Comments
 (0)