#!/usr/bin/env python3 """HTML-резюме из JSON.""" from __future__ import annotations import argparse import html import json from pathlib import Path SAMPLE = { "name": "Имя Фамилия", "title": "Специалист по данным", "email": "user@example.com", "phone": "+1 555 0100", "site": "https://example.com", "summary": "Короткий абзац о профессиональном опыте и интересах.", "skills": ["Python", "SQL", "Визуализация данных"], "experience": [ { "company": "Example Company", "role": "Аналитик", "start": "2023-01", "end": "настоящее время", "bullets": ["Собирал отчёты", "Автоматизировал рутину"], } ], "education": [ {"school": "Example University", "degree": "Прикладная информатика", "year": "2022"} ], } def esc(value) -> str: return html.escape(str(value)) def render(data: dict) -> str: skills = "".join(f"
  • {esc(item)}
  • " for item in data.get("skills", [])) experience = [] for job in data.get("experience", []): bullets = "".join(f"
  • {esc(item)}
  • " for item in job.get("bullets", [])) experience.append( "
    " f"

    {esc(job.get('role', ''))}

    " f"
    {esc(job.get('company', ''))} · {esc(job.get('start', ''))} - {esc(job.get('end', ''))}
    " f"" "
    " ) education = "".join( f"
  • {esc(item.get('school', ''))}, {esc(item.get('degree', ''))}, {esc(item.get('year', ''))}
  • " for item in data.get("education", []) ) return f""" {esc(data.get('name', 'Резюме'))}

    {esc(data.get('name', ''))}

    {esc(data.get('title', ''))}
    {esc(data.get('email', ''))} · {esc(data.get('phone', ''))} · {esc(data.get('site', ''))}

    О себе

    {esc(data.get('summary', ''))}

    Навыки

    Опыт

    {''.join(experience)}

    Образование

    """ def main() -> int: parser = argparse.ArgumentParser(description="Резюме из JSON") parser.add_argument("--data", type=Path) parser.add_argument("--output", type=Path, default=Path("resume.html")) parser.add_argument("--init", action="store_true") parser.add_argument("--force", action="store_true") args = parser.parse_args() if args.init: output = args.output.expanduser() if output.exists() and not args.force: parser.error(f"Файл уже существует: {output}") output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(SAMPLE, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") print(f"Пример резюме сохранён: {output}") return 0 if not args.data: parser.error("Укажите --data или --init") source = args.data.expanduser() if not source.is_file(): parser.error(f"Файл не найден: {source}") try: data = json.loads(source.read_text(encoding="utf-8")) except json.JSONDecodeError as error: parser.error(f"Ошибка JSON: {error}") if not isinstance(data, dict): parser.error("Корень JSON должен быть объектом") output = args.output.expanduser() if output.suffix.lower() != ".html": parser.error("Поддерживается только расширение .html") if output.exists() and not args.force: parser.error(f"Файл уже существует: {output}. Добавьте --force.") output.parent.mkdir(parents=True, exist_ok=True) output.write_text(render(data), encoding="utf-8") print(f"Резюме сохранено: {output}") return 0 if __name__ == "__main__": raise SystemExit(main())