Huginn 实用指南:让你的网络生活自动化起来

天天

发布于231天前
龙猫也是猫
## Huginn 到底是个啥?

简单说,Huginn 就是你的私人 IFTTT(If This Then That),一个可以在你自己服务器上运行的自动化工具。 不过相比 IFTTT,它更强大、更自由,当然也稍微有点技术门槛。

这个名字来自北欧神话,奥丁有两只乌鸦,其中一只叫 Huginn(代表"思想"),每天飞出去收集信息向主人汇报。 


https://appstore.lazycat.cloud/#/shop/detail/lazycat.app.huginn


### 核心概念很简单

Huginn 的运作原理就像工厂流水线:每个 Agent(代理)就像流水线上的工人,负责一个特定任务。把多个 Agent 串联起来,就组成了一条完整的自动化流水线。

- **Agent**:执行具体任务的单元,比如"监控网页"、"发送邮件"
- **Event**:Agent 之间传递的数据
- **Scenario**:一组相关 Agent 的集合,就是你的自动化方案

## 手把手实战:监控技术博客并生成自己的 RSS 源

让我们来个完整的实战案例:监控多个技术博客,汇总后生成一个新的 RSS 源,你可以用任何 RSS 阅读器订阅。

应用打开后,默认账号密码是 `admin/password`。

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/68b3bc4b-7e9c-498e-ab59-8453eba29e12.png "image.png")
   
### Step 1:创建 RSS Agent 监控博客

1. **登录 Huginn 后,点击 "Agents" → "New Agent"**

2. **选择 Agent 类型**
   - Type 选择:`Rss Agent`
   - Name:`监控猫哥的博客`
   - Schedule:`every_2h`(每 2 小时检查一次)
   - Keep events:`20`(保留最近 20 条记录)

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/77f85bb9-4c18-40a4-ad7b-1b2a20f0589f.png "image.png")
3. **配置 Options**

```json
{
  "expected_update_period_in_days": "5",
  "clean": "false",
  "url": "https://manateelazycat.github.io/feed.xml"
}
```

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/ffdc05c3-deaa-4f61-a968-678c0ee95e5c.png "image.png")
4. **点击 "Dry Run" 测试**
   - 应该能看到博客的文章列表
   - 每篇文章包含 title、url、description 等字段

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/c31b89f9-a458-43ee-ba77-0fec6af9c3f5.png "image.png")
### Step 2:创建文章处理 Agent(添加标签)

使用 Event Formatting Agent 为文章添加来源标签。

1. **新建 Agent**
   - Type:`Event Formatting Agent`
   
![image.png](https://dl.playground.lazycat.cloud/guidelines/496/cff2ced8-ac9d-4418-ab8b-f52804910e47.png "image.png")
   - Name:`格式化文章数据`
   - Sources:选择上面的 RSS Agent


![image.png](https://dl.playground.lazycat.cloud/guidelines/496/72b45c1e-4a1e-4687-82ee-240844e7111f.png "image.png")
2. **配置 Options**

```json
{
  "instructions": {
    "title": "【猫哥博客】{{title}}",
    "url": "{{url}}",
    "description": "{{description}}",
    "author": "{{author | default: 'ManateeLazyCat'}}",
    "source": "ManateeLazyCat Blog",
    "pubDate": "{{pubDate}}"
  },
  "mode": "clean",
  "matchers": [],
  "skip_created_at": "false"
}
```

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/e7eca0b3-0c33-47d8-8478-8994bc133cc1.png "image.png")
### Step 3:监控更多 RSS 源(可选)

创建更多 RSS Agent 监控其他博客:

**监控阮一峰的博客:**
```json
{
  "expected_update_period_in_days": "7",
  "clean": "false",
  "url": "http://www.ruanyifeng.com/blog/atom.xml"
}
```

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/76a67049-7920-4291-96d3-970914582469.png "image.png")
**监控 Hacker News:**
```json
{
  "expected_update_period_in_days": "1",
  "clean": "false",
  "url": "https://news.ycombinator.com/rss"
}
```

为每个源创建对应的 Event Formatting Agent,添加不同的标签。

### Step 4:汇总所有文章

1. **新建 Agent**
   - Type:`Digest Agent`
   - Name:`汇总所有文章`
   - Sources:选择所有的 Event Formatting Agent

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/2c3c5411-20f3-438b-8644-a58e46488303.png "image.png")


![image.png](https://dl.playground.lazycat.cloud/guidelines/496/4e001541-571f-46f6-b34f-0e634df5a9a3.png "image.png")
2. **配置 Options**

```json
{
  "expected_update_period_in_days": "1",
  "message": "{% for event in events %}\n\n  {{ event.title | xml_escape }}\n  {{ event.url | xml_escape }}\n  {{ event.description | xml_escape }}\n  {{ event.pubDate }}\n  {{ event.source }}\n\n{% endfor %}",
  "retained_events": "100"
}
```

### Step 5:生成 RSS 输出

1. **新建 Agent**
   - Type:`Data Output Agent`
   - Name:`输出RSS源`
   - Sources:选择汇总 Agent

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/ee072f1c-29b9-48fc-b064-b5054c452cfa.png "image.png")
2. **配置 Options**

```json
{
  "secrets": ["my_secret_token"],
  "expected_receive_period_in_days": "2",
  "template": {
    "title": "我的技术资讯聚合",
    "description": "聚合多个技术博客的 RSS",
    "link": "https://huginn.懒猫.heiyu.space/",
    "item": {
      "title": "{{title}}",
      "description": "{{description}}",
      "link": "{{url}}",
      "pubDate": "{{pubDate}}",
      "guid": "{{url}}"
    }
  },
  "events_to_show": "50",
  "response_headers": {
    "Content-Type": "application/rss+xml; charset=utf-8"
  }
}
```

3. **获取你的 RSS 地址**
   - 保存后,在 Agent 详情页会显示一个链接
   - 格式类似:`http://你的域名/users/1/web_requests/xxx/my_secret_token.xml`
   - 用任何 RSS 阅读器订阅这个地址即可!

![image.png](https://dl.playground.lazycat.cloud/guidelines/496/27592709-1923-4fc5-93de-0ba2fc85c43e.png "image.png")
 

### 完整的工作流程图

```
监控博客RSS (Rss Agent) → 格式化数据 (Event Formatting Agent) → 
      ↓
监控其他RSS (Rss Agent) → 格式化数据 (Event Formatting Agent) → 

汇总 (Digest Agent)
      ↓
输出RSS (Data Output Agent)
      ↓
你的RSS阅读器订阅
```
 
配置完成后:
1. Huginn 自动监控多个博客
2. 汇总生成一个新的 RSS 源
3. 你用 RSS 阅读器订阅这个源
4. 所有博客更新都在一个地方查看

这样你就有了一个完全由自己控制的技术资讯聚合器。
 
## 写在最后

Huginn 确实需要一点技术基础,刚开始可能会觉得有点复杂,但当你成功设置第一个自动化任务,看到它默默为你工作时,那种成就感真的很棒。而且一旦上手,你会发现越来越多的使用场景,生活和工作效率都会大大提升。
 

祝你玩得开心,让 Huginn 成为你的数字生活小助手!

---

**相关资源:**
- [Huginn GitHub 仓库](https://github.com/huginn/huginn)
- [官方文档](https://github.com/huginn/huginn/wiki)

评论

0

暂无评论

说点什么呢~
收藏
0
0
0