Communitygithub.com

CSV 報告撰寫器

將任務的結果字典列表轉換為帶有結構的 CSV 和 Markdown 表格,只需一份欄位規格 - 一次性宣告欄位,同時產出兩者,具有穩定的排序與安全的跳脫處理,僅使用標準函式庫,無需 pandas。當使用者要求將結果寫入 CSV、匯出報告、製作 Markdown 摘要表格或將任務輸出存成試算表時使用。

CSV 報告撰寫器 是什麼?

此技能提供一個輕量級的 Python 輔助模組,可從單一欄位定義同時產生結構化的 CSV 檔案與 Markdown 表格,確保兩種輸出格式的欄位順序與數據內容完全一致,避免人工維護對應時的誤差。它設計給需要在 Terminal、CI/CD 或 Telegram 摘要中快速產出報表的開發者使用,特別是在無法安裝 pandas 或 polars 的受限環境中。支援宣告式欄位規格 (包含自訂格式器)、穩定的欄位排序、CSV 正確的引號跳脫、Markdown 管線與換行跳脫,以及對缺失鍵值的安全處理。使用者只需呼叫 `write_csv()` 與 `to_markdown()` 函式,即可將 `list[dict]` 數據同時輸出為 CSV (適合試算表) 與 Markdown 表格 (適合 PR 評論或訊息)。此技能適用於 Claude Code、Codex 等允許自訂工具與檔案的平台,並且完全依賴 Python 標準函式庫。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/baronguyen001/ai-automation-skills/tree/HEAD/skills/csv-report-writer

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

CSV 報告撰寫器 是做什麼的?

當任務產生一系列結果行,而您想要一份可供試算表使用的整潔 CSV,外加一個用於 PR 評論或 Telegram 摘要的 Markdown 表格時,請使用此技能——只需一份欄位定義,兩種輸出便不會產生偏差。您一次性宣告欄位(鍵名、標題、選擇性格式化器);輔助函式會自動產出兩者,並維持穩定的欄位順序、正確的 CSV 引號跳脫以及 Markdown 的管線跳脫。無需 pandas。

何時呼叫

  • 使用者說:「將結果寫入 CSV」、「匯出報告」、「為此內容製作 Markdown 表格」、「將任務輸出存成試算表」。
  • 對話中的程式碼有一個 list[dict](或物件列表),但目前只是隨意印出。

何時不應呼叫

  • 數據需要真正的資料框操作——合併、分組、樞紐分析;此時請改用 pandas/polars。
  • 只有單一純量結果,使用 CSV/表格過於繁瑣。

具體範例

使用者輸入:

我有一個掃描到的代幣列表,包含分數與價格。請儲存一份 CSV,同時給我一張 Markdown 表格用於 Telegram 摘要。

輸出:

# 將 assets/report.py 複製到您的專案中,然後:
from report import Column, write_csv, to_markdown

columns = [
    Column("symbol", "Symbol"),
    Column("score", "Score", fmt=lambda v: f"{v:.1f}"),
    Column("price_usd", "Price", fmt=lambda v: f"${v:,.4f}"),
]
rows = [
    {"symbol": "ABC", "score": 8.4, "price_usd": 0.0123},
    {"symbol": "XYZ", "score": 6.1, "price_usd": 1.5},
]

write_csv("scan.csv", columns, rows)        # 結構化 CSV,穩定的欄位順序
print(to_markdown(columns, rows))           # 同樣的欄位,Markdown 表格

兩種輸出使用完全相同的欄位與完全相同的順序,所以 CSV 與摘要表格始終保持一致。

適用模式

  1. 一次性宣告每個 Column(key, header, fmt=...);兩個寫入器都使用同一個列表,因此標題與順序保持一致。
  2. 保持欄位順序穩定且明確——不要依賴任意行的字典插入順序。
  3. 讓 fmt 可呼叫物件負責呈現格式(貨幣、四捨五入);將原始值儲存在行字典中。
  4. 使用 csv.writer 進行正確的引號跳脫;為 Markdown 表格跳脫 | 與換行,以免破壞版面。
  5. 將缺失的鍵視為空白儲存格而非觸發錯誤,這樣部分行仍能被呈現。

參考檔案:assets/report.py。

來源

由作者在生產環境中跨多個自動化專案的使用經驗萃取而成。v1.0.0。 另請參見:[[pr-body-formatter]]、[[sqlite-state]]、[[telegram-alerter]]。

→ 使用 Trawlkit 建立完整可執行的機器人。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

baronguyen001/ai-automation-skills

Schedule any script to run on a recurring schedule on Windows (Task Scheduler) or Linux (cron) - register, list, and remove jobs from one command, with logging to a file and a guard against overlapping runs. Use for schedule a script, run nightly, set up a cron job, windows task scheduler, or run on a timer.

baronguyen001/ai-automation-skills

Strip HTML to clean plain text with the standard library only (no BeautifulSoup/lxml): drops script/style, turns block tags into line breaks, and collapses whitespace. Use when the user wants readable text from an HTML page/email, to clean scraped HTML before sending it to an LLM, or to build a text index from web content.

baronguyen001/ai-automation-skills

Persist records between scheduled runs as append-only JSON Lines (one object per line) with streaming reads and optional key-based dedup, stdlib only. Use when the user wants to log run results to JSONL, append events to a file, dedup records by id across runs, or keep a simple durable history without a database.

baronguyen001/ai-automation-skills

Extract text and simple table-like rows from a PDF for downstream AI without OCR binaries. Use when the user asks to read a PDF, turn a PDF into text, pull simple tables from statements/reports, or feed PDF content into an LLM pipeline.

baronguyen001/ai-automation-skills

Rotate a pool of HTTP/SOCKS proxies with round-robin selection, failure tracking, and a cooldown that benches dead proxies before retrying. BYO proxy list via env - none are shipped. Use for rotate proxies, spread requests across proxies, avoid IP bans, retry through a different proxy, or proxy health check.

baronguyen001/ai-automation-skills

Parse an RSS 2.0 or Atom feed into normalized item dicts (title, link, id, published, summary) with the standard library only - no feedparser. Use when the user asks to read an RSS/Atom feed, poll a blog/news feed, extract feed entries, or watch a site that publishes a feed.

baronguyen001/ai-automation-skills

Upload and download run artifacts from S3-compatible storage with BYO bucket and credentials from env. Use when the user asks to store scraper output, archive reports, publish artifacts to object storage, fetch a prior run file, or use MinIO/R2/Spaces/S3 without hardcoding credentials.

baronguyen001/ai-automation-skills

Draft a short-form TikTok/Reels/Shorts or long-form video script from a topic and creator persona file - hook variants, beat-structured body, CTA, b-roll cues, caption overlays, and [STORY]/[NUMBER] slots so the model never fabricates personal facts. Use for write a video script, tiktok script, youtube script, or /shortform-script.

baronguyen001/ai-automation-skills

Give scheduled scripts memory between runs with one SQLite file - a seen-set for dedup, a key/value cursor to resume where you left off, and order-preserving new-item filtering. Use for dedup across runs, don't re-alert the same item, remember the last id, resume a scraper, or persist state between cron runs.

相關技能