Total Pageviews

Monday 29 August 2016

执行自动化任务的工具-Huginn

What is Huginn?

Huginn is a system for building agents that perform automated tasks for you online. They can read the web, watch for events, and take actions on your behalf. Huginn's Agents create and consume events, propagating them along a directed graph. Think of it as a hackable Yahoo! Pipes plus IFTTT on your own server. You always know who has your data. You do.
the origin of the name

Here are some of the things that you can do with Huginn:

  • Track the weather and get an email when it's going to rain (or snow) tomorrow ("Don't forget your umbrella!")
  • List terms that you care about and receive emails when their occurrence on Twitter changes. (For example, want to know when something interesting has happened in the world of Machine Learning? Huginn will watch the term "machine learning" on Twitter and tell you when there is a spike in discussion.)
  • Watch for air travel or shopping deals
  • Follow your project names on Twitter and get updates when people mention them
  • Scrape websites and receive emails when they change
  • Connect to Adioso, HipChat, Basecamp, Growl, FTP, IMAP, Jabber, JIRA, MQTT, nextbus, Pushbullet, Pushover, RSS, Bash, Slack, StubHub, translation APIs, Twilio, Twitter, Wunderground, and Weibo, to name a few.
  • Send digest emails with things that you care about at specific times during the day
  • Track counts of high frequency events and send an SMS within moments when they spike, such as the term "san francisco emergency"
  • Send and receive WebHooks
  • Run custom JavaScript or CoffeeScript functions
  • Track your location over time
  • Create Amazon Mechanical Turk workflows as the inputs, or outputs, of agents (the Amazon Turk Agent is called the "HumanTaskAgent"). For example: "Once a day, ask 5 people for a funny cat photo; send the results to 5 more people to be rated; send the top-rated photo to 5 people for a funny caption; send to 5 final people to rate for funniest caption; finally, post the best captioned photo on my blog."
Gitter Changelog #199
Join us in our Gitter room to discuss the project and follow @tectonic for updates as Huginn evolves.

Join us!

Want to help with Huginn? All contributions are encouraged! You could make UI improvements, add new Agents, write documentation and tutorials, or try tackling issues tagged with #help-wanted. Please fork, add specs, and send pull requests!
Really want a fix or feature? Want to solve some community issues and earn some extra coffee money? Take a look at the current bounties on Bountysource.
Have an awesome idea but not feeling quite up to contributing yet? Head over to our Official 'suggest an agent' thread and tell us!

Examples

Please checkout the Huginn Introductory Screencast!
And now, some example screenshots. Below them are instructions to get you started.
Example list of agents
Event flow diagram
Making a new agent

Getting Started

Docker

The quickest and easiest way to check out Huginn is to use the official Docker image. Have a look at the documentation.

Local Installation

If you just want to play around, you can simply fork this repository, then perform the following steps:
  • Run git remote add upstream https://github.com/cantino/huginn.git to add the main repository as a remote for your fork.
  • Copy .env.example to .env (cp .env.example .env) and edit .env, at least updating the APP_SECRET_TOKENvariable.
  • Run bundle to install dependencies
  • Run bundle exec rake db:createbundle exec rake db:migrate, and then bundle exec rake db:seed to create a development MySQL database with some example Agents.
  • Run bundle exec foreman start, visit http://localhost:3000/, and login with the username of admin and the password of password.
  • Setup some Agents!
  • Read the wiki for usage examples and to get started making new Agents.
  • Periodically run git fetch upstream and then git checkout master && git merge upstream/master to merge in the newest version of Huginn.
Note: By default, emails are intercepted in the development Rails environment, which is what you just setup. You can view them at http://localhost:3000/letter_opener. If you'd like to send real emails via SMTP when playing with Huginn locally, set SEND_EMAIL_IN_DEVELOPMENT to true in your .env file.
If you need more detailed instructions, see the Novice setup guide.

Nitrous Quickstart

You can quickly create a free development environment for this Huginn project in the cloud on www.nitrous.io:
Nitrous Quickstart
In the IDE, start Huginn via Run > Start Huginn and access your site via Preview > 3000.

Develop

All agents have specs! And there's also acceptance tests that simulate running Huginn in a headless browser. 
  • Install PhantomJS 2.1.1 or greater: 
  • Run all specs with bundle exec rspec
  • Run a specific spec with bundle exec rspec path/to/specific/test_spec.rb
  • Read more about rspec for rails here.

Deployment

Heroku

Try Huginn on Heroku: Deploy (Takes a few minutes to setup. Read the documentation while you are waiting and be sure to click 'View it' after launch!)
Huginn works on the free version of Heroku with significant limitations. For non-experimental use, we strongly recommend Heroku's cheapest paid plan or our Docker container.
Please see the Huginn Wiki for detailed deployment strategies for different providers.

Manual installation on any server

Have a look at the installation guide.

Optional Setup

Setup for private development

Enable the WeatherAgent

In order to use the WeatherAgent you need an API key with Wunderground. Signup for one and then change the value of api_key: your-key in your seeded WeatherAgent.

Disable SSL

We assume your deployment will run over SSL. This is a very good idea! However, if you wish to turn this off, you'll probably need to edit config/initializers/devise.rb and modify the line containing config.rememberable_options = { :secure => true }. You will also need to edit config/environments/production.rb and modify the value of config.force_ssl。
from https://github.com/cantino/huginn
-----
相关帖子: https://briteming.blogspot.com/2017/10/huginn.html
-----

huginn|全网数据监控与通知工具—安装教程


今天发现了一个特别棒的工具—huginn,很实用,应用范围很广,确实是网络工具库中的神器。它可以监控网络上的一切资源,并将这些资源按照你的需要发送给你。实现这一功能只需要简单的配置就可以了。列举一下,huginn 主要的应用场景和功能。

1 跟没有 RSS 的网站定制 RSS 种子

2 监控知乎、微博、贴吧等平台指定的信息,一旦监控到信息,邮件通知你本人

3 监控各大购物平台商品信息,一旦发现折扣信息,邮件通知你

4 支持各种形式的发送和接收 WebHooks。

Huginn 就是私有的 IFTTT,自定义程度非常高,只要你思路开阔,想法够野一定能发挥出巨大的价值。

Huginn 安装

Huginn 的安装方法有很多种,我推荐一种,就是通过 docker 安装。原因很简单,安装快,而且这本身就是 docker 的主要应用场景和优势所在。如果是常规安装方式,需要安装依赖包、ruby 环境、数据库、nginx、huginn 及各种配置;但是 docker 就只需要下载 docker 镜像,运行 huginn 容器就可以了。

1 安装 docker

建议最低配置为 1G 内存、1 核 CPU。推荐使用 vultr 的基础款云服务器,自带一键安装 docker 功能。均采用千兆带宽、SSD 硬盘,稳定性有保障,按小时计费,随用随停,且支持支付宝付款。

Centos7 安装 docker 命令如下:

  1. curl -fsSL https://get.docker.com/ | sh
  2. systemctl start docker
  3. systemctl status docker
  4. systemctl enable docker

注:安装 docker 要求系统内核版本高于 3.0,基本上只能安装在 KVM 架构的 vps 上。

2 运行 huginn 容器

  1. docker run  --name huginn  -p 3000:3000 huginn/huginn

注:重启容器会导致数据丢失,请勿轻易应用到生产环境。

Huginn 界面

部署成功后访问 IP+3000 端口,出现界面,点击登录,默认账号密码是 admin/password.登录成功。

Huginn 使用介绍-以 website agent 采集网页为例

简单通过一个例子介绍下 huginn 的使用方法。监控 v2ex 首页第一个帖子,首页第一个帖子变化时,发送邮件通知。

1 新建一个 agent,负责每隔一分钟采集 v2ex 第一个帖子的标题,配置如下。点击 agents->new agent .

type 选择 website agent,表示从 web 站点采集数据;

name 是这个 agent 的名称

schedule 表示多久采集一次,本次设置的是每分钟一次

其他的暂时不用管,重要的是配置 option,即从 v2ex 采集第一个帖子的规则。

需要配置采集地址 url,即 v2ex 首页的网址;v2ex 第一个帖子的 css 定位,可以通过 f12 查看帖子的 xpath,但是获取的 xpath 经常有问题,推荐通过 selectorgadget chrome 扩展去获取定位;再配置获取的内容,我是获取的文字内容,填 normalize-space(.)即可.

最后点击“dry run” 测试一下是否可以获取到内容,下图所示即成功。点击 save,保存该 agent.

运行几分钟后,可以看到每分钟都能获取到新的 v2ex 帖子。

使用邮件通知 email agent

通过以上 v2ex agent 实现了每隔一分钟检测一次首页第一个帖子。然后再尝试一下将 v2ex agent 中的内容通过邮件发布。

需要另外新建一个 agent,type 选择 Email Agent,sources 选择我们之前创建的 v2ex agent,options 中填邮件内容,我们通过{{title}}引入了 v2ex agent 中的 title 字段。这样 v2ex agent 每次检测到内容更新,就会触发 email agent,将更新的内容通过邮件发送到本人。

另外,还需要配置邮件发送server接收相关内容。

首先要配置stmp 服务器。然后将 stmp 配置信息写到 huginn 容器的环境变量中去。所以需要用以下方式启动 huginn 容器:

  1. docker run  --name huginn \
  2. -p 3000:3000 \
  3. -e SMTP_DOMAIN=163.com \
  4. -e SMTP_USER_NAME=AAAAAA@163.com \
  5. -e SMTP_PASSWORD=password \
  6. -e SMTP_SERVER=smtp.163.com \
  7. -e EMAIL_FROM_ADDRESS= AAAAAA @163.com \
  8. huginn/huginn

其次,配置接收邮件人。

点击界面右上角的 account,将默认的邮箱 admin@example.com,改为接收邮箱号,邮件配置就完成了.