Skip to content

Commit

Permalink
update examples (#123)
Browse files Browse the repository at this point in the history
Signed-off-by: rmdg88 <[email protected]>
  • Loading branch information
rmdg88 authored Oct 3, 2024
1 parent d44c62d commit dde0aff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions examples/batch_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ def export_documents(
doc_filename = conv_res.input.file.stem

# Export Deep Search document JSON format:
with (output_dir / f"{doc_filename}.json").open("w") as fp:
with (output_dir / f"{doc_filename}.json").open(
"w", encoding="utf-8"
) as fp:
fp.write(json.dumps(conv_res.render_as_dict()))

# Export Text format:
with (output_dir / f"{doc_filename}.txt").open("w") as fp:
with (output_dir / f"{doc_filename}.txt").open("w", encoding="utf-8") as fp:
fp.write(conv_res.render_as_text())

# Export Markdown format:
with (output_dir / f"{doc_filename}.md").open("w") as fp:
with (output_dir / f"{doc_filename}.md").open("w", encoding="utf-8") as fp:
fp.write(conv_res.render_as_markdown())

# Export Document Tags format:
with (output_dir / f"{doc_filename}.doctags").open("w") as fp:
with (output_dir / f"{doc_filename}.doctags").open(
"w", encoding="utf-8"
) as fp:
fp.write(conv_res.render_as_doctags())

elif conv_res.status == ConversionStatus.PARTIAL_SUCCESS:
Expand Down
12 changes: 8 additions & 4 deletions examples/custom_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ def export_documents(
doc_filename = conv_res.input.file.stem

# Export Deep Search document JSON format:
with (output_dir / f"{doc_filename}.json").open("w") as fp:
with (output_dir / f"{doc_filename}.json").open(
"w", encoding="utf-8"
) as fp:
fp.write(json.dumps(conv_res.render_as_dict()))

# Export Text format:
with (output_dir / f"{doc_filename}.txt").open("w") as fp:
with (output_dir / f"{doc_filename}.txt").open("w", encoding="utf-8") as fp:
fp.write(conv_res.render_as_text())

# Export Markdown format:
with (output_dir / f"{doc_filename}.md").open("w") as fp:
with (output_dir / f"{doc_filename}.md").open("w", encoding="utf-8") as fp:
fp.write(conv_res.render_as_markdown())

# Export Document Tags format:
with (output_dir / f"{doc_filename}.doctags").open("w") as fp:
with (output_dir / f"{doc_filename}.doctags").open(
"w", encoding="utf-8"
) as fp:
fp.write(conv_res.render_as_doctags())

else:
Expand Down

0 comments on commit dde0aff

Please sign in to comment.