#!/usr/bin/env python3
import subprocess
import sys
import os

def parse_resume(pdf_path):
    """
    使用mineru解析PDF简历，返回markdown格式内容
    """
    if not os.path.exists(pdf_path):
        return f"错误：文件 {pdf_path} 不存在"
    
    # 调用mineru解析PDF
    try:
        result = subprocess.run(
            ["mineru", "parse", pdf_path, "--format", "markdown"],
            capture_output=True,
            text=True,
            check=True
        )
        return result.stdout
    except subprocess.CalledProcessError as e:
        return f"解析失败：{e.stderr}"
    except FileNotFoundError:
        return "错误：未找到mineru命令，请先安装mineru工具"

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("用法：python parse_resume.py <简历PDF路径>")
        sys.exit(1)
    
    pdf_path = sys.argv[1]
    content = parse_resume(pdf_path)
    print(content)
