# 数据写入工具

> 将用户提供的文本数据自动解析并写入项目的JSON文件

- **Type:** Skill
- **Install:** `agentstack add skill-hhhh124hhhh-skillmate-content-data-manager`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [hhhh124hhhh](https://agentstack.voostack.com/s/hhhh124hhhh)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [hhhh124hhhh](https://github.com/hhhh124hhhh)
- **Source:** https://github.com/hhhh124hhhh/SkillMate/tree/main/resources/skills/content-data-manager

## Install

```sh
agentstack add skill-hhhh124hhhh-skillmate-content-data-manager
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 数据写入工具

用于将用户从公众号后台或其他来源复制粘贴的数据，自动解析并保存到项目的JSON文件中。

## 📌 核心功能

### 1. 数据解析
- **自动识别**：智能识别文章标题、阅读量、发布时间等信息
- **多种格式**：支持公众号后台粘贴、表格格式、列表格式等
- **数据清洗**：自动去除空行、特殊字符，标准化数据格式

### 2. 数据验证
- **必填检查**：确保标题、发布时间等关键字段完整
- **格式校验**：验证日期格式、数字格式等
- **重复检测**：检查是否已存在相同标题的文章

### 3. 数据写入
- **JSON格式**：以结构化JSON格式保存
- **追加模式**：支持追加新数据，保留原有数据
- **备份机制**：写入前自动备份原文件

### 4. 数据统计
- **阅读量分析**：总阅读量、平均阅读量、最高/最低阅读量
- **时间分析**：发布时间分布、频率统计
- **趋势分析**：近期阅读量趋势

## 🚀 使用方式

### 方式1：使用Python直接调用

```python
from data_writer import handler

# 用户粘贴的数据（模拟从公众号后台复制）
user_data = """
别再写水文了！这套AI写作SOP让逻辑硬核起飞
原创
29412100
2025年12月10日
已发表
2025 年 12 月 AI 年终盘点(一)
11917000
2025年11月29日
"""

args = {
    "action": "write_articles",
    "data": user_data,
    "output_file": "articles_data.json"
}

result = handler(args)
print(result)
```

**返回示例**：

```json
{
  "status": "success",
  "message": "成功写入 2 篇文章",
  "articles_written": 2,
  "articles_skipped": 0,
  "output_file": "articles_data.json",
  "statistics": {
    "total_articles": 10,
    "total_reading": 12345678,
    "avg_reading": 1234567
  }
}
```

### 方式2：通过命令行使用

```bash
# 将数据保存到临时文件，然后运行
echo "你的粘贴数据" > temp_data.txt
python data_writer.py --input temp_data.txt --output articles_data.json
```

### 方式3：使用交互式输入

```python
from data_writer import handler

# 交互式输入
print("请粘贴文章数据（按Ctrl+Z或Ctrl+D结束输入）:")
user_data = []
while True:
    try:
        line = input()
        user_data.append(line)
    except EOFError:
        break

data_str = "\n".join(user_data)

result = handler({
    "action": "write_articles",
    "data": data_str,
    "output_file": "articles_data.json"
})
```

## 📋 数据格式说明

### 支持的输入格式

#### 格式1：公众号后台粘贴格式（推荐）
```
文章标题
原创/非原创
阅读量
发布日期（年/月/日）
已发表
文章标题2
...
```

#### 格式2：表格格式
```
标题 | 原创 | 阅读量 | 发布日期
文章标题 | 原创 | 29412100 | 2025-12-10
文章标题2 | 原创 | 11917000 | 2025-11-29
```

#### 格式3：列表格式
```
1. 别再写水文了！这套AI写作SOP让逻辑硬核起飞 (29412100, 2025-12-10)
2. 2025 年 12 月 AI 年终盘点(一) (11917000, 2025-11-29)
```

## 🔧 函数说明

### parse_article_data(data: str)
解析用户粘贴的原始数据

**参数：**
- `data`: 用户粘贴的原始文本数据

**返回：**
- 解析后的文章列表

**示例：**
```python
articles = parse_article_data(user_data)
# 返回: [{'title': '...', 'original': '原创', 'reading': 29412100, 'date': '2025-12-10'}]
```

### write_to_json(articles: List[Dict], output_file: str)
将文章数据写入JSON文件

**参数：**
- `articles`: 文章列表
- `output_file`: 输出文件路径

**返回：**
- 写入结果字典

### validate_article(article: Dict)
验证单篇文章数据

**参数：**
- `article`: 文章字典

**返回：**
- (是否有效, 错误信息)

### check_duplicate(articles: List[Dict], new_articles: List[Dict])
检查重复文章

**参数：**
- `articles`: 原有文章列表
- `new_articles`: 新文章列表

**返回：**
- 去重后的新文章列表

### generate_statistics(articles: List[Dict])
生成统计数据

**参数：**
- `articles`: 文章列表

**返回：**
- 统计信息字典

### handler(args: Dict)
主处理函数

**参数：**
- `args`: 包含以下字段的字典
  - `action`: 操作类型（write_articles/parse_data/validate_data/statistics）
  - `data`: 原始数据（write_articles时必需）
  - `output_file`: 输出文件路径（可选，默认articles_data.json）
  - `append`: 是否追加模式（可选，默认True）

**返回：**
- 处理结果

## 📊 输出文件格式

写入的JSON文件格式：

```json
{
  "metadata": {
    "created": "2026-01-10 13:00:00",
    "last_updated": "2026-01-10 13:00:00",
    "total_articles": 10
  },
  "articles": [
    {
      "id": 1,
      "title": "别再写水文了！这套AI写作SOP让逻辑硬核起飞",
      "original": true,
      "reading": 29412100,
      "date": "2025-12-10",
      "platform": "微信",
      "created_at": "2026-01-10 13:00:00"
    },
    {
      "id": 2,
      "title": "2025 年 12 月 AI 年终盘点(一)",
      "original": true,
      "reading": 11917000,
      "date": "2025-11-29",
      "platform": "微信",
      "created_at": "2026-01-10 13:00:00"
    }
  ],
  "statistics": {
    "total_reading": 41329100,
    "avg_reading": 20664550,
    "max_reading": {
      "title": "别再写水文了！这套AI写作SOP让逻辑硬核起飞",
      "reading": 29412100
    },
    "min_reading": {
      "title": "2025 年 12 月 AI 年终盘点(一)",
      "reading": 11917000
    },
    "original_count": 2,
    "original_rate": 1.0
  }
}
```

## 💡 最佳实践

### 1. 数据准备
- 从公众号后台"发表记录"页面复制
- 确保包含标题、阅读量、发布时间
- 避免包含无关内容（如页码、跳转按钮等）

### 2. 数据验证
- 检查解析结果是否正确
- 确认阅读量格式（纯数字或带单位）
- 验证日期格式

### 3. 数据管理
- 定期备份数据文件
- 定期清理重复数据
- 建立版本控制

### 4. 数据分析
- 分析高阅读量文章的共同特征
- 找出发布时间与阅读量的关系
- 总结爆款选题规律

## ⚠️ 注意事项

### 数据质量
1. **完整性**：确保标题、阅读量、发布时间完整
2. **准确性**：检查阅读量是否正确
3. **一致性**：保持数据格式一致

### 文件安全
1. **备份**：写入前自动备份原文件
2. **权限**：确保有写入权限
3. **路径**：使用相对路径或绝对路径

### 错误处理
1. **重复**：检测并提示重复文章
2. **格式**：提示格式错误
3. **空值**：检查必填字段

## 🎯 应用场景

1. **公众号运营**：定期备份文章数据
2. **内容分析**：分析文章表现
3. **选题研究**：根据历史数据优化选题
4. **数据可视化**：为数据可视化工具准备数据

## 📈 使用效果

使用本工具可以：
- **节省时间**：90%的数据录入时间
- **减少错误**：99%的数据准确率
- **提高效率**：批量处理数百篇文章
- **便于分析**：结构化数据便于统计分析

---

**使用本工具时，请确保数据来源合法合规，避免侵犯他人权益！**

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [hhhh124hhhh](https://github.com/hhhh124hhhh)
- **Source:** [hhhh124hhhh/SkillMate](https://github.com/hhhh124hhhh/SkillMate)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-hhhh124hhhh-skillmate-content-data-manager
- Seller: https://agentstack.voostack.com/s/hhhh124hhhh
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
