@@ -34,40 +34,29 @@ def _init_api(self, credentials_file: Path):
34
34
except (FileNotFoundError , json .JSONDecodeError , ValueError ) as e :
35
35
logging .error (f"Failed to load credentials: { e } " )
36
36
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
-
44
37
def upload_document (self ):
45
38
"""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 } " )
55
46
56
47
def get_bookmark (self ):
57
48
"""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 } " )
69
58
70
59
if __name__ == "__main__" :
71
60
pdf_bookmarks = PdfBookmarks ()
72
61
pdf_bookmarks .upload_document ()
73
- pdf_bookmarks .get_bookmark ()
62
+ pdf_bookmarks .get_bookmark ()
0 commit comments