Verify PowerPoint presentation contents using python-pptx via shell when standard file readers fail
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-pptx-shell-verify-7707ef2b783d ,按照其中的说明把「pptx-shell-verify」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill when:
read_file or other built-in tools fail to read PowerPoint (.pptx) filespython-pptx library available (install if needed)First, try to read the file using standard methods:
read_file: path/to/presentation.pptx
If this fails or returns unusable data, proceed to Step 2.
Check if the library is installed:
run_shell: python -c "import pptx; print('pptx available')"
If not available, install it:
run_shell: pip install python-pptx
Create a Python script to extract presentation metadata:
# verify_pptx.py
from pptx import Presentation
import sys
import json
def verify_presentation(filepath):
try:
prs = Presentation(filepath)
data = {
"slide_count": len(prs.slides),
"slides": []
}
for i, slide in enumerate(prs.slides):
slide_data = {
"slide_number": i + 1,
"title": None,
"shapes_count": len(slide.shapes)
}
# Extract title if present
if slide.shapes.title:
slide_data["title"] = slide.shapes.title.text
data["slides"].append(slide_data)
print(json.dumps(data, indent=2))
return True
except Exception as e:
print(f"ERROR: {str(e)}", file=sys.stderr)
return False
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python verify_pptx.py <file.pptx>", file=sys.stderr)
sys.exit(1)
success = verify_presentation(sys.argv[1])
sys.exit(0 if success else 1)
Run the verification script:
run_shell: python verify_pptx.py path/to/presentation.pptx
Expected output format:
{
"slide_count": 10,
"slides": [
{
"slide_number": 1,
"title": "Introduction",
"shapes_count": 3
},
...
]
}
Use this data to:
# Check slide count matches requirement
assert data["slide_count"] >= expected_min_slides
# Check all slides have titles
for slide in data["slides"]:
assert slide["title"] is not None, f"Slide {slide['slide_number']} missing title"
| Issue | Solution |
|---|---|
| Corrupted file | Verify file was created successfully, check file size |
| Permission denied | Ensure file path is accessible, check read permissions |
| Library not found | Install with pip install python-pptx |
| Empty presentation | File may be 0 bytes or incomplete write |