Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/save document converter result #157

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

absadiki
Copy link

Hello,
Thanks for the awesome package :)

This is a simple PR that adds a new save method to the DocumentConverterResult class, making it easier to save the converted document result to a file.

Changes:

  • Added a save method to the DocumentConverterResult class, which takes a file_path and optional encoding parameter. The method writes the text_content to the specified file using the specified encoding.
  • Updated the sample script in the README file to showcase the new save method.

@absadiki
Copy link
Author

@microsoft-github-policy-service agree

Comment on lines +149 to +159
def save(self, file_path: str, encoding: str = "utf-8") -> None:
"""
Save the converted document result `text_content` to a file.

params:
file_path: The path to save the document result to.
encoding: The encoding to use when writing the document.
"""
with open(file_path, "w", encoding=encoding) as f:
f.write(self.text_content)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it serves the same purpose as #116. could you refactor the code to use a single function for better reusability?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure @l-lumin,

I think it makes more sense to have the function to save the result into a file inside the DocumentConverterResult.

  • I refactored the CLI to use this function.
  • I also added an encoding parameter to the arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I think so too. Look good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants