MENU

利用 Huginn 将微信公众号转化为 RSS 订阅

June 22, 2017 • Read: 11613 • 应用

搭建 Huginn

Docker 与 Daocloud

安装 Docker。

curl -sSL https://get.daocloud.io/docker | sh

或者可以通过包管理安装,就是版本可能会旧一点。

sudo apt install docker.io

添加当前用户到 docker 用户组。

sudo usermod -aG docker user

安装 Daomonit。

curl -sSL https://get.daocloud.io/daomonit/install.sh | sh -s *******

部署 Huginn 容器

在 Daocloud 内添加好主机好,去发现镜像里搜索 Huginn,使用新版的 huginn/huginn,部署即可,注意将 3000 端口暴露出来,因为容器默认是跑在 3000 端口上的,如果主机没有跑别的网站的话,也可以直接暴露在 80 上。

Nginx 反代

用端口访问总是麻烦一点,做个反代,新建一个 vhost,编辑其设置。

server {
    listen 80;
    server_name xxx.xxx.com;
    access_log  /var/log/nginx/access.log;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

操作 Huginn

参考 这篇文章

点击下载 Scenario

{
  "schema_version": 1,
  "name": "微信公众号",
  "description": "No description provided",
  "source_url": false,
  "guid": "c0be876a712baf52fa4270d6b1744432",
  "tag_fg_color": "#ffffff",
  "tag_bg_color": "#00b050",
  "icon": "leaf",
  "exported_at": "2017-05-28T02:35:18Z",
  "agents": [
    {
      "type": "Agents::DeDuplicationAgent",
      "name": "微信公众号 #3 去除重复",
      "disabled": false,
      "guid": "3250efcc923ce4c10b30763c6e0365b6",
      "options": {
        "property": "{{title}}",
        "lookback": "0",
        "expected_update_period_in_days": "20"
      },
      "keep_events_for": 15552000,
      "propagate_immediately": true
    },
    {
      "type": "Agents::WebsiteAgent",
      "name": "微信公众号 #2 获取文章列表",
      "disabled": false,
      "guid": "606e3875f2368e053aace5f3d9ceeb9d",
      "options": {
        "expected_update_period_in_days": "20",
        "url": "https://phantomjscloud.com/api/browser/v2/{% credential phantomjs_cloud %}/?request={url:\"{{url | replace: '&', '%26'}}\",renderType:\"html\"}",
        "type": "html",
        "mode": "on_change",
        "extract": {
          "url": {
            "css": "h4",
            "value": "@hrefs"
          },
          "title": {
            "css": "h4",
            "value": "string(.)"
          }
        },
        "events_order": [
          [
            "{{_index_}}",
            "number",
            "true"
          ]
        ],
        "template": {
          "url": "{{ url | to_uri: \"http://mp.weixin.qq.com\" }}"
        }
      },
      "schedule": "never",
      "keep_events_for": 7776000,
      "propagate_immediately": true
    },
    {
      "type": "Agents::WebsiteAgent",
      "name": "微信公众号 #1 搜索账号",
      "disabled": false,
      "guid": "a4c7bc9e333c38cbb4fdfa3a24c191ed",
      "options": {
        "expected_update_period_in_days": "4",
        "_comment": [
          "利器",
          "PingWest品玩",
          "经济学人",
          "译读",
          "爱思想的青年",
          "苔原",
          "连岳",
          "新京报传媒研究",
          "鲤newriting",
          "看理想",
          "取经号JTW",
          "星期天读书会",
          "译读小号二世",
          "京师心理大学堂"
        ],
        "url": [
          "http://weixin.sogou.com/weixin?query=liqiio",
          "http://weixin.sogou.com/weixin?query=wepingwest",
          "http://weixin.sogou.com/weixin?query=TheEconomistGroup",
          "http://weixin.sogou.com/weixin?query=T-Read",
          "http://weixin.sogou.com/weixin?query=asxdqn",
          "http://weixin.sogou.com/weixin?query=the_tundra",
          "http://weixin.sogou.com/weixin?query=ilianyue",
          "http://weixin.sogou.com/weixin?query=xjbcmyj",
          "http://weixin.sogou.com/weixin?query=newriting200806",
          "http://weixin.sogou.com/weixin?query=ikanlixiang",
          "http://weixin.sogou.com/weixin?query=JTWest",
          "http://weixin.sogou.com/weixin?query=SundayReading",
          "http://weixin.sogou.com/weixin?query=WinnieTheFool",
          "http://weixin.sogou.com/weixin?query=bnupsychology"
        ],
        "type": "html",
        "mode": "on_change",
        "extract": {
          "url": {
            "css": ".news-box > ul > li:first-child .tit a",
            "value": "@href"
          }
        }
      },
      "schedule": "every_1d",
      "keep_events_for": 86400,
      "propagate_immediately": false
    },
    {
      "type": "Agents::DataOutputAgent",
      "name": "微信公众号 #5 输出RSS",
      "disabled": false,
      "guid": "cbc2ced20c71d435a5bd375b3e580797",
      "options": {
        "secrets": [
          "weixin_public"
        ],
        "expected_receive_period_in_days": "20",
        "template": {
          "title": "微信公众号",
          "description": "微信公众号",
          "item": {
            "title": "【{{author}}】{{title}}",
            "description": "{{ desciption | replace: 'data-src', 'src' }}",
            "link": "{{url}}"
          },
          "link": "https://weixin.sogou.com/",
          "icon": "https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/common/favicon22c41b.ico"
        },
        "ns_media": "true",
        "events_to_show": "300"
      },
      "propagate_immediately": true
    },
    {
      "type": "Agents::WebsiteAgent",
      "name": "微信公众号 #4 获取单篇文章全文",
      "disabled": false,
      "guid": "f7c52fcd85cea0d7426978202f4dc692",
      "options": {
        "expected_update_period_in_days": "20",
        "url_from_event": "https://phantomjscloud.com/api/browser/v2/{% credential phantomjs_cloud %}/?request={url:\"{{url | replace: '&', '%26'}}\",renderType:\"html\"}",
        "type": "html",
        "mode": "merge",
        "extract": {
          "desciption": {
            "css": "#js_content",
            "value": "./node()"
          },
          "author": {
            "css": "#post-user",
            "value": "string(.)"
          },
          "title": {
            "css": "#activity-name",
            "value": "string(.)"
          }
        }
      },
      "schedule": "never",
      "keep_events_for": 604800,
      "propagate_immediately": true
    }
  ],
  "links": [
    {
      "source": 0,
      "receiver": 4
    },
    {
      "source": 1,
      "receiver": 0
    },
    {
      "source": 2,
      "receiver": 1
    },
    {
      "source": 4,
      "receiver": 3
    }
  ],
  "control_links": [

  ]
}

申请一个 phantomjs_cloud 的 key,填入 Credentials 里,类型选 Text。

导入 Scenarios,编辑想要的公众号,运行第一个 Agent,RSS 地址在最后一个 Agent内。

有点 bug,微信的图片有防盗链。。。显示不出来。。。。
Archives QR Code
QR Code for this page
Tipping QR Code
Leave a Comment

3 Comments
  1. eric eric

    想问下脚本还能正常运行吗?

    1. @eric不清楚,很久没用过了。

  2. 支持下