pdf-capa-code

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: Montagem de PDFs com Capa — VDE Concursos (Claude Code)

Skill:带封面的PDF组装 — VDE Concursos(Claude Code)

Referência completa (casos extremos, troubleshooting, decisões de design):
references/complete-skill.md

完整参考(极端情况、故障排查、设计决策):
references/complete-skill.md

Configuração

配置

yaml
SECOES: ["Teoria Sistematizada", "Caderno de Lei"]
RADICAL_FINALIZADOS: "FINALIZADO"   # matching case-insensitive, sem 's'
RADICAL_DESTINO: "VERSÃO FINAL"     # ou "versao final"
PREFIXO_CAPA: "#CAPA"               # PDF nativo no Drive

yaml
SECOES: ["Teoria Sistematizada", "Caderno de Lei"]
RADICAL_FINALIZADOS: "FINALIZADO"   # 不区分大小写匹配,不带's'
RADICAL_DESTINO: "VERSÃO FINAL"     # 或 "versao final"
PREFIXO_CAPA: "#CAPA"               # Drive 中的原生 PDF 文件

Pré-requisitos

前置要求

bash
gws --version && gws auth status 2>&1
token_valid
deve ser
true
. Se não estiver, ver
references/complete-skill.md
.
Sempre incluir nos params do gws:
"supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives"

bash
gws --version && gws auth status 2>&1
token_valid
需为
true
。如果不是,请查看
references/complete-skill.md
gws 的参数中请始终包含:
"supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives"

Execução

执行步骤

1 — Extrair folder ID da URL

1 — 从 URL 中提取文件夹 ID

https://drive.google.com/drive/u/1/folders/ABC123 → ID = ABC123
https://drive.google.com/drive/u/1/folders/ABC123 → ID = ABC123

2 — Listar subpastas da disciplina

2 — 列出学科的子文件夹

bash
gws drive files list --params '{"q": "\"FOLDER_ID\" in parents and mimeType=\"application/vnd.google-apps.folder\"", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
Filtrar por
"teoria sistematizada"
e
"caderno de lei"
(case-insensitive).
bash
gws drive files list --params '{"q": "\"FOLDER_ID\" in parents and mimeType=\"application/vnd.google-apps.folder\"", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
筛选出
"teoria sistematizada"
"caderno de lei"
(不区分大小写)。

3 — Por seção: coletar IDs (repetir para cada seção)

3 — 按章节收集 ID(每个章节重复执行)

a) Subpastas internas:
bash
gws drive files list --params '{"q": "\"SECAO_ID\" in parents and mimeType=\"application/vnd.google-apps.folder\"", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
  • FINALIZADO_ID
    name.lower()
    contém
    "finalizado"
  • VERSAO_FINAL_ID
    name.lower()
    contém
    "versão final"
    ou
    "versao final"
b) Capa (buscar na raiz da seção; se o usuário indicou que está no FINALIZADO, usar
capa_id: null
):
bash
gws drive files list --params '{"q": "\"SECAO_ID\" in parents and name contains \"#CAPA\" and mimeType=\"application/pdf\"", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
c) Documentos em FINALIZADO:
bash
gws drive files list --params '{"q": "\"FINALIZADO_ID\" in parents and (mimeType=\"application/vnd.google-apps.document\" or mimeType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.document\")", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name,mimeType)"}' 2>&1
d) Arquivos já na VERSÃO FINAL:
bash
gws drive files list --params '{"q": "\"VERSAO_FINAL_ID\" in parents", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
a) 内部子文件夹:
bash
gws drive files list --params '{"q": "\"SECAO_ID\" in parents and mimeType=\"application/vnd.google-apps.folder\"", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
  • FINALIZADO_ID
    name.lower()
    包含
    "finalizado"
  • VERSAO_FINAL_ID
    name.lower()
    包含
    "versão final"
    "versao final"
b) 封面(在章节根目录搜索;如果用户说明封面在 FINALIZADO 文件夹中,则设置
capa_id: null
):
bash
gws drive files list --params '{"q": "\"SECAO_ID\" in parents and name contains \"#CAPA\" and mimeType=\"application/pdf\"", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1
c) FINALIZADO 文件夹中的文档:
bash
gws drive files list --params '{"q": "\"FINALIZADO_ID\" in parents and (mimeType=\"application/vnd.google-apps.document\" or mimeType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.document\")", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name,mimeType)"}' 2>&1
d) 已存放在 VERSÃO FINAL 文件夹中的文件:
bash
gws drive files list --params '{"q": "\"VERSAO_FINAL_ID\" in parents", "supportsAllDrives": true, "includeItemsFromAllDrives": true, "corpora": "allDrives", "fields": "files(id,name)"}' 2>&1

4 — Executar o script (repetir para cada seção)

4 — 执行脚本(每个章节重复执行)

Copiar o script (só na primeira seção):
bash
cp '<SKILL_DIR>/scripts/process_batch.py' /tmp/process_batch.py
Escrever o config e executar:
bash
python3 -c "
import json
config = {
  'capa_id': 'ID_DA_CAPA',                   # null → script busca #CAPA em capa_fallback_folder_id
  'capa_fallback_folder_id': 'FINALIZADO_ID',
  'versao_final_id': 'ID_DA_VERSAO_FINAL',
  'existing_files': ['arquivo1.pdf'],
  'docs': [
    {'id': 'DOC_ID', 'name': '1. Nome', 'mimeType': 'application/vnd.google-apps.document'}
  ]
}
open('/tmp/batch_config_SECAO_ID.json', 'w').write(json.dumps(config, ensure_ascii=False, indent=2))
"
python3 /tmp/process_batch.py /tmp/batch_config_SECAO_ID.json 2>&1
复制脚本(仅首次处理章节时需要):
bash
cp '<SKILL_DIR>/scripts/process_batch.py' /tmp/process_batch.py
写入配置并执行:
bash
python3 -c "
import json
config = {
  'capa_id': 'ID_DA_CAPA',                   # null → 脚本会在 capa_fallback_folder_id 中搜索 #CAPA
  'capa_fallback_folder_id': 'FINALIZADO_ID',
  'versao_final_id': 'ID_DA_VERSAO_FINAL',
  'existing_files': ['arquivo1.pdf'],
  'docs': [
    {'id': 'DOC_ID', 'name': '1. Nome', 'mimeType': 'application/vnd.google-apps.document'}
  ]
}
open('/tmp/batch_config_SECAO_ID.json', 'w').write(json.dumps(config, ensure_ascii=False, indent=2))
"
python3 /tmp/process_batch.py /tmp/batch_config_SECAO_ID.json 2>&1

5 — Resultado consolidado

5 — 汇总结果

Disciplina · DD/MM/AAAA

📚 Teoria Sistematizada  (N docs)
  ✓ X enviados · ○ Y já existiam

📚 Caderno de Lei  (N docs)
  ✓ X enviados
Erros (
): listar causa e oferecer reprocessar apenas os que falharam.

Disciplina · DD/MM/AAAA

📚 Teoria Sistematizada  (N docs)
  ✓ X 已提交 · ○ Y 已存在

📚 Caderno de Lei  (N docs)
  ✓ X 已提交
错误(
):列出错误原因,并提供仅重新处理失败项的选项。

Erros frequentes

常见错误

SintomaAção rápida
gws: command not found
npm install -g @googleworkspace/cli
token_valid: false
gws auth login
ModuleNotFoundError: pypdf
pip3 install pypdf
Capa não encontradaNome começa com
#CAPA
? É PDF nativo?
insufficientFilePermissions
Verificar acesso de Editor no Drive
Ver
references/troubleshooting.md
e
references/complete-skill.md
para casos avançados.
现象快速解决方法
gws: command not found
npm install -g @googleworkspace/cli
token_valid: false
gws auth login
ModuleNotFoundError: pypdf
pip3 install pypdf
未找到封面文件名是否以
#CAPA
开头?是否为原生 PDF 文件?
insufficientFilePermissions
检查 Drive 的编辑权限
如需处理高级情况,请查看
references/troubleshooting.md
references/complete-skill.md