MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / write_poster_texts

Function write_poster_texts

get_poster_text.py:7–47  ·  view source on GitHub ↗

For each immediate subfolder of `root_folder`, look for a file named `poster.png`. If found, call `get_poster_text(path)` and save the returned text to `poster_text.md` in that same subfolder. Returns a summary dict with counts and any errors.

(root_folder: str | Path)

Source from the content-addressed store, hash-verified

5import os
6
7def write_poster_texts(root_folder: str | Path) -> dict:
8 """
9 For each immediate subfolder of `root_folder`, look for a file named `poster.png`.
10 If found, call `get_poster_text(path)` and save the returned text to `poster_text.md`
11 in that same subfolder.
12
13 Returns a summary dict with counts and any errors.
14 """
15 root = Path(root_folder)
16 processed = 0
17 missing = 0
18 errors: list[tuple[Path, str]] = []
19
20 for subdir in root.iterdir():
21 if not subdir.is_dir():
22 continue
23 if os.path.exists(subdir / "poster_text.md"):
24 print(f"Skipping {subdir.name} as poster_text.md already exists.")
25 continue
26 print(f"Processing {subdir.name}...")
27
28 poster_path = subdir / "poster.png"
29 if not poster_path.exists():
30 print(f"Missing poster.png in {subdir.name}.")
31 missing += 1
32 continue
33
34 try:
35 text = get_poster_text(poster_path, False) # assumes this function is available
36 out_path = subdir / "poster_text.md"
37 # Ensure we always write UTF-8 with a trailing newline.
38 Path(out_path).write_text((text or "").rstrip() + "\n", encoding="utf-8")
39 processed += 1
40 except Exception as e: # keep going even if one folder fails
41 errors.append((poster_path, str(e)))
42
43 return {
44 "processed": processed,
45 "missing_poster_png": missing,
46 "errors": errors,
47 }
48
49if __name__ == "__main__":
50 parser = argparse.ArgumentParser(description="Extract poster texts from images.")

Callers 1

get_poster_text.pyFile · 0.70

Calls 1

get_poster_textFunction · 0.90

Tested by

no test coverage detected