Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compare two or more Word documents using a REST API in Python
Compare two or more Word documents using a REST API in Python
client_id = "112f0f38-9dae-42d5-b4fc-cc84ae644972"
client_secret = "16ad3fe0bdc39c910f57d2fd48a5d618"
my_storage = ""
configuration = groupdocs_comparison_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
# Create necessary API instances
api_instance = groupdocs_comparison_cloud.CompareApi.from_keys(client_id, client_secret)
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source.docx"
target1 = groupdocs_comparison_cloud.FileInfo()
target1.file_path = "target.docx"
target2 = groupdocs_comparison_cloud.FileInfo()
target2.file_path = "target2.docx"
options = groupdocs_comparison_cloud.ComparisonOptions()
options.source_file = source
options.target_files = [target1, target2]
options.output_path = "Output/result.docx"
request = groupdocs_comparison_cloud.ComparisonsRequest(options)
response = api_instance.comparisons(request)
# Create necessary API instances
api_instance = groupdocs_comparison_cloud.CompareApi.from_keys(client_id, client_secret)
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source.docx"
target = groupdocs_comparison_cloud.FileInfo()
target.file_path = "target.docx"
options = groupdocs_comparison_cloud.ComparisonOptions()
options.source_file = source
options.target_files = [target]
options.output_path = "Output/result.docx"
request = groupdocs_comparison_cloud.ComparisonsRequest(options)
response = api_instance.comparisons(request)
# Create instance of the API
file_api = groupdocs_comparison_cloud.FileApi.from_config(configuration)
request = groupdocs_comparison_cloud.DownloadFileRequest("Output\\result.docx", my_storage)
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\")
settings = groupdocs_comparison_cloud.Settings()
# Compare sensitivity
settings.sensitivity_of_comparison = 100
# Customize styles for the changes
settings.inserted_items_style = groupdocs_comparison_cloud.ItemsStyle()
settings.inserted_items_style.highlight_color = "14297642"
settings.inserted_items_style.font_color = "16711680"
settings.inserted_items_style.underline = True
settings.deleted_items_style = groupdocs_comparison_cloud.ItemsStyle()
settings.deleted_items_style.font_color = "14166746"
settings.deleted_items_style.bold = True
settings.changed_items_style = groupdocs_comparison_cloud.ItemsStyle()
settings.changed_items_style.font_color = "14320170"
settings.changed_items_style.italic = True
options.settings = settings
# api initialization
file_api = groupdocs_comparison_cloud.FileApi.from_config(configuration)
storage_api = groupdocs_comparison_cloud.StorageApi.from_config(configuration)
# upload sample files
for filename in glob.iglob("C:\\Files\\*.docx", recursive=True):
destFile = filename.replace("C:\\Files\\", "", 1)
fileExistsResponse = storage_api.object_exists(groupdocs_comparison_cloud.ObjectExistsRequest(destFile))
if not fileExistsResponse.exists:
file_api.upload_file(groupdocs_comparison_cloud.UploadFileRequest(destFile, filename))
print("Uploaded file: "+ destFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment