|
1 |
| -import shutil |
| 1 | + import shutil |
2 | 2 | import json
|
3 | 3 | import logging
|
4 | 4 | from pathlib import Path
|
@@ -32,36 +32,25 @@ def _init_api(self, credentials_file: Path):
|
32 | 32 | except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
|
33 | 33 | logging.error(f"init_api(): Failed to load credentials: {e}")
|
34 | 34 |
|
35 |
| - def _ensure_api_initialized(self): |
36 |
| - """ Check if the API is initialized before making API calls. """ |
37 |
| - if not self.pdf_api: |
38 |
| - logging.error("ensure_api_initialized(): PDF API is not initialized. Operation aborted.") |
39 |
| - return False |
40 |
| - return True |
41 |
| - |
42 | 35 | def upload_document(self):
|
43 | 36 | """ Upload a PDF document to the Aspose Cloud server. """
|
44 |
| - if not self._ensure_api_initialized(): |
45 |
| - return |
46 |
| - |
47 |
| - file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME |
48 |
| - try: |
49 |
| - self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) |
50 |
| - logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") |
51 |
| - except Exception as e: |
52 |
| - logging.error(f"upload_document(): Failed to upload file: {e}") |
| 37 | + if self.pdf_api: |
| 38 | + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME |
| 39 | + try: |
| 40 | + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) |
| 41 | + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") |
| 42 | + except Exception as e: |
| 43 | + logging.error(f"upload_document(): Failed to upload file: {e}") |
53 | 44 |
|
54 | 45 | def get_document_words_count_on_pages(self):
|
55 | 46 | """ Retrieves the word count for each page in a PDF document. """
|
56 |
| - if not self._ensure_api_initialized(): |
57 |
| - return |
58 |
| - |
59 |
| - response: WordCountResponse = self.pdf_api.get_words_per_page(Config.PDF_DOCUMENT_NAME) |
60 |
| - |
61 |
| - if response.code == 200: |
62 |
| - logging.info(response.words_per_page.list) |
63 |
| - else: |
64 |
| - logging.error("Failed to retrieve word count.") |
| 47 | + if self.pdf_api: |
| 48 | + response: WordCountResponse = self.pdf_api.get_words_per_page(Config.PDF_DOCUMENT_NAME) |
| 49 | + |
| 50 | + if response.code == 200: |
| 51 | + logging.info(response.words_per_page.list) |
| 52 | + else: |
| 53 | + logging.error("Failed to retrieve word count.") |
65 | 54 | return
|
66 | 55 |
|
67 | 56 | if __name__ == "__main__":
|
|
0 commit comments