Skip to content

tw93/Waza / plugins/waza/skills/read

Fetches URLs and PDFs, then summarizes or returns clean Markdown; can also search the web through DeepSeek when built-in search is thin. Use when asked to read, fetch, quote, cite, convert, or save a URL or PDF. Not for local text files already in the repo.

FileKindSize
SKILL.mdskill md7.7 KB
references/read-methods.mdmarkdown5.2 KB
scripts/deepseek.pyscript3.9 KB
scripts/fetch.shscript3.9 KB
scripts/fetch_feishu.pyscript8.9 KB
scripts/fetch_local.pyscript7.1 KB
scripts/fetch_weixin.pyscript3.6 KB

scripts/fetch_feishu.py

View on GitHub
#!/usr/bin/env python3
"""Fetch Feishu/Lark document as Markdown via Feishu Open API.

Special thanks to joeseesun for the excellent qiaomu-markdown-proxy project,
which inspired the Feishu API integration and document parsing approach here.
https://github.com/joeseesun/qiaomu-markdown-proxy

Default path:
    pip install requests

Setup:
    export FEISHU_APP_ID=your_app_id
    export FEISHU_APP_SECRET=your_app_secret
    App needs: docx:document:readonly, wiki:wiki:readonly

Alternative user-login path:
    npm install -g @larksuite/cli
    lark-cli auth login
    lark-cli docs +fetch --doc <feishu_url>

Usage:
    python3 fetch_feishu.py <feishu_url>
    python3 fetch_feishu.py <feishu_url> --json
"""

import sys
import json
import os
import re
import urllib.parse

try:
    import requests
except ImportError:
    requests = None

API = "https://open.feishu.cn/open-apis"
TIMEOUT = 20
LARK_CLI_HINT = (
    "For user-login access instead of app credentials, install/configure lark-cli "
    "(npm install -g @larksuite/cli && lark-cli auth login), then run "
    "lark-cli docs +fetch --doc <feishu_url>."
)


def yaml_string(value):
    return json.dumps("" if value is None else str(value), ensure_ascii=False)


def get_token():
    app_id = os.environ.get("FEISHU_APP_ID")
    app_secret = os.environ.get("FEISHU_APP_SECRET")
    missing = []
    if requests is None:
        missing.append("Python package requests not installed; run: pip install requests")
    if not app_id or not app_secret:
        missing.append("FEISHU_APP_ID or FEISHU_APP_SECRET not set")
    if missing:
        return None, "; ".join(missing) + f". {LARK_CLI_HINT}"
    resp = requests.post(f"{API}/auth/v3/tenant_access_token/internal",
                         json={"app_id": app_id, "app_secret": app_secret},
                         timeout=TIMEOUT)
    d = resp.json()
    if d.get("code") != 0:
        return None, f"Auth failed: {d.get('msg', resp.text)}"
    return d["tenant_access_token"], None


def parse_url(url):
    patterns = [
        (r"feishu\.cn/docx/([A-Za-z0-9]+)", "docx"),
        (r"feishu\.cn/docs/([A-Za-z0-9]+)", "legacy_doc"),
        (r"feishu\.cn/wiki/([A-Za-z0-9]+)", "wiki"),
        (r"larksuite\.com/docx/([A-Za-z0-9]+)", "docx"),
        (r"larksuite\.com/docs/([A-Za-z0-9]+)", "legacy_doc"),
        (r"larksuite\.com/wiki/([A-Za-z0-9]+)", "wiki"),
    ]
    for pattern, doc_type in patterns:
        m = re.search(pattern, url)
        if m:
            return m.group(1), doc_type
    return url, "docx"


def resolve_wiki(token, wiki_token):
    resp = requests.get(f"{API}/wiki/v2/spaces/get_node",
                        headers={"Authorization": f"Bearer {token}"},
                        params={"token": wiki_token},
                        timeout=TIMEOUT)
    d = resp.json()
    if d.get("code") == 0:
        node = d["data"]["node"]
        return node.get("obj_token"), node.get("obj_type")
    return None, None


def get_blocks(token, doc_id):
    blocks, page_token = [], None
    while True:
        params = {"page_size": 500}
        if page_token:
            params["page_token"] = page_token
        resp = requests.get(f"{API}/docx/v1/documents/{doc_id}/blocks",
                            headers={"Authorization": f"Bearer {token}"},
                            params=params,
                            timeout=TIMEOUT)
        d = resp.json()
        if d.get("code") != 0:
            return None, f"Blocks fetch failed: {d.get('msg', resp.text)}"
        blocks.extend(d["data"].get("items", []))
        if not d["data"].get("has_more"):
            break
        page_token = d["data"].get("page_token")
    return blocks, None


def extract_text(elements):
    if not elements:
        return ""
    parts = []
    for el in elements:
        if "text_run" in el:
            tr = el["text_run"]
            text = tr.get("content", "")
            s = tr.get("text_element_style", {})
            if s.get("bold"):        text = f"**{text}**"
            if s.get("italic"):      text = f"*{text}*"
            if s.get("inline_code"): text = f"`{text}`"
            if s.get("link", {}).get("url"):
                text = f"[{text}]({urllib.parse.unquote(s['link']['url'])})"
            parts.append(text)
        elif "mention_user" in el:
            parts.append(f"@{el['mention_user'].get('user_id', 'user')}")
        elif "equation" in el:
            parts.append(f"${el['equation'].get('content', '')}$")
    return "".join(parts)


LANG_MAP = {
    7: "bash", 8: "c", 9: "csharp", 10: "cpp", 14: "css", 19: "dockerfile",
    25: "go", 29: "html", 31: "java", 32: "javascript", 33: "json",
    35: "kotlin", 40: "markdown", 46: "php", 50: "python", 52: "ruby",
    53: "rust", 58: "sql", 59: "swift", 62: "typescript", 68: "xml", 69: "yaml",
}


def blocks_to_md(blocks):
    lines = []
    counters = {}
    for block in blocks:
        bt = block.get("block_type")
        pid = block.get("parent_id", "")

        if bt == 2:
            text = extract_text(block.get("text", {}).get("elements", []))
            lines.append(text if text.strip() else "")
        elif bt in range(3, 10):
            level = bt - 2
            key = f"heading{level}"
            data = block.get(key) or block.get("heading", {})
            text = extract_text(data.get("elements", []))
            lines.append(f"{'#' * min(level, 6)} {text}")
        elif bt == 10:
            text = extract_text(block.get("bullet", {}).get("elements", []))
            lines.append(f"- {text}")
        elif bt == 11:
            text = extract_text(block.get("ordered", {}).get("elements", []))
            n = counters.get(pid, 0) + 1
            counters[pid] = n
            lines.append(f"{n}. {text}")
        elif bt == 12:
            code_data = block.get("code", {})
            text = extract_text(code_data.get("elements", []))
            lang = LANG_MAP.get(code_data.get("style", {}).get("language", 0), "")
            lines.extend([f"```{lang}", text, "```"])
        elif bt == 13:
            text = extract_text(block.get("quote", {}).get("elements", []))
            lines.append(f"> {text}")
        elif bt == 15:
            todo_data = block.get("todo", {})
            text = extract_text(todo_data.get("elements", []))
            done = todo_data.get("style", {}).get("done", False)
            lines.append(f"- {'[x]' if done else '[ ]'} {text}")
        elif bt == 16:
            lines.append("---")
        elif bt == 17:
            tok = block.get("image", {}).get("token", "")
            lines.append(f"![image](feishu-image://{tok})")
        elif bt == 1:
            pass
        else:
            for key, val in block.items():
                if isinstance(val, dict) and "elements" in val:
                    text = extract_text(val["elements"])
                    if text.strip():
                        lines.append(text)
                    break

    return "\n\n".join(lines)


def fetch_feishu(url):
    doc_id, doc_type = parse_url(url)

    if doc_type == "legacy_doc":
        return {
            "error": (
                "Legacy Feishu /docs/ pages are not supported by this script. "
                "Convert the document to docx first, or use a public-page fallback if the page is accessible without the API."
            )
        }

    token, err = get_token()
    if err:
        return {"error": err}

    if doc_type == "wiki":
        real_id, real_type = resolve_wiki(token, doc_id)
        if not real_id:
            return {"error": f"Cannot resolve wiki node: {doc_id}"}
        doc_id, doc_type = real_id, real_type or "docx"

    info_resp = requests.get(f"{API}/docx/v1/documents/{doc_id}",
                             headers={"Authorization": f"Bearer {token}"},
                             timeout=TIMEOUT)
    doc_info = (info_resp.json().get("data") or {}).get("document") or {}
    title = doc_info.get("title", "")

    blocks, err = get_blocks(token, doc_id)
    if err:
        return {"error": err}

    return {"title": title, "document_id": doc_id, "url": url, "content": blocks_to_md(blocks)}


def to_markdown(r):
    if "error" in r:
        return f"Error: {r['error']}"
    parts = [
        "---",
        f"title: {yaml_string(r.get('title', ''))}",
        f"document_id: {yaml_string(r.get('document_id', ''))}",
        f"url: {yaml_string(r.get('url', ''))}",
        "---",
        "",
        f"# {r['title']}" if r.get("title") else "",
        "",
        r.get("content", ""),
    ]
    return "\n".join(parts)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: fetch_feishu.py <feishu_url> [--json]", file=sys.stderr)
        print("  Default requires: pip install requests plus FEISHU_APP_ID and FEISHU_APP_SECRET", file=sys.stderr)
        print(f"  Alternative: {LARK_CLI_HINT}", file=sys.stderr)
        sys.exit(1)

    result = fetch_feishu(sys.argv[1])
    if "--json" in sys.argv:
        print(json.dumps(result, ensure_ascii=False, indent=2))
    else:
        print(to_markdown(result))
    if "error" in result:
        sys.exit(1)
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 195kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 195kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 195kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 195kUpdated Claude CodeCodexVerifiedInstall