Files
slide-translate/main.py
nite 3eef042111 refactor(app): Extract PDF conversion logic into a separate module
The main.py script was becoming monolithic, containing all the logic for PDF conversion, image path simplification, and content refinement. This change extracts these core functionalities into a new `pdf_convertor` module.

This refactoring improves the project structure by:
- Enhancing modularity and separation of concerns.
- Making the main.py script a cleaner, high-level orchestrator.
- Improving code readability and maintainability.

The functions `convert_pdf_to_markdown`, `save_md_images`, and `refine_content` are now imported from the `pdf_convertor` module and called from the main execution block.
2025-10-27 20:02:02 +11:00

38 lines
969 B
Python
Executable File

import os
from pdf_convertor import (
convert_pdf_to_markdown,
save_md_images,
refine_content,
)
from pathlib import Path
def main():
input_dir = Path("input")
output_dir = Path("output")
output_dir.mkdir(parents=True, exist_ok=True)
for filename in os.listdir(input_dir):
if not filename.endswith(".pdf"):
continue
pdf_path = input_dir.joinpath(filename)
current_output_dir = output_dir.joinpath(
pdf_path.name.removesuffix(pdf_path.suffix)
)
current_output_dir.mkdir(parents=True, exist_ok=True)
print(f"Processing {pdf_path} -> {current_output_dir}")
with open(pdf_path, "rb") as pdf_file:
pdf_content = pdf_file.read()
md, images = convert_pdf_to_markdown(pdf_content)
md = refine_content(md, images, pdf_content)
save_md_images(current_output_dir, md, images)
if __name__ == "__main__":
main()