Fork me on GitHub

目录:

最近互联网理财很流行, 好的理财产品一出来很快就抢光了。有24x7运行的低功耗树莓派在就可以帮你检查网页是否有更新并将更新的内容通知到你的手机上。

安装phantomjs

https://github.com/piksel/phantomjs-raspberrypi 下载已经编译好的phatomjs,并复制到$PATH

安装Node.js

在树莓派上编译Node.js非常非常耗时。。。你也可以下载已经编译好的node和npm

wget https://s3-eu-west-1.amazonaws.com/conoroneill.net/wp-content/uploads/2015/02/node-v0.12.0-linux-arm-pi.tar.gz
tar -zxvf node-v0.12.0-linux-arm-pi.tar.gz
cd node-v0.12.0-linux-arm-pi
sudo cp -R * /usr/local/

执行npm install phantom安装phantom模块,这个模块要求phantomjs被安装在$PATH下。

编写监视网页的脚本

var phantom = require('phantom');

phantom.create(function (ph) {
	ph.createPage(function (page) {
		page.open('http://8.wacai.com/list/fund', function(status) {
			if (status!='success') {
				console.log('network error');
			} else {
				// page.includeJs("http://code.jquery.com/jquery-1.11.2.min.js", function() {
					var data = page.evaluate(function(){
						var str = "";
						$(".fundItem").each(function(index) {
							txt = $(this).text().trim().replace(/\s+/g," ");
							str = str + "\n"+ index + " : " + txt;
						})
						return str;
					}, function(result) {
						console.log(result);
						ph.exit();
					});
				// });
			}
		});		
	});
});

执行后的结果

hugo@raspberrypi phantomjs $ node wacai.js 

0 : 新手专享 新手项目1号 年化收益 10.00% 已购人数28121人 起购金额100元 投资期限 10天 立即申购 本息保障
1 : 车盈宝133号 年化收益 6.50% 投资总额493.84万 投资进度 % 投资期限 29天 剩余金额199.07万 立即申购 本息保障
2 : 理财宝日常版1号 年化收益 9.00% 已购人数14031人 起购金额100元 投资期限 178天 立即申购 本息保障
3 : 理财宝日常版2号 年化收益 10.00% 已购人数167842人 起购金额100元 投资期限 322天 立即申购 本息保障
4 : 新手专享 新手项目2号 年化收益 10.00% 已购人数33468人 起购金额100元 投资期限 14天 已售罄 本息保障
5 : 盈信宝11号 年化收益 8.50% 投资总额458.97万 投资进度 % 投资期限 91天 已申购人数500人 已售罄 本息保障 限量抢购
6 : 聚财宝18号 年化收益 8.00% 投资总额750万 投资进度 % 投资期限 90天 已申购人数465人 已售罄 本息保障
7 : 宝盈货币A 七日年化收益4.880% 万份收益2.1065元 近一年收益率5.009% 起购金额100元 立即申购 超低风险
8 : 长安货币A 七日年化收益5.791% 万份收益1.1816元 近一年收益率4.908% 起购金额1000元 立即申购 超低风险
9 : 国泰货币 七日年化收益4.164% 万份收益1.1661元 近一年收益率4.136% 起购金额100元 立即申购 超低风险
10 : 工银货币 七日年化收益4.422% 万份收益1.4558元 近一年收益率4.568% 起购金额100元 立即申购 超低风险
11 : 国泰180ETF联接 近一年收益率72.150% 昨日涨跌幅-0.098% 昨日净值1.4309元 起购金额1000元 立即申购 高风险高收益
12 : 大摩多因子策略股票 近一年收益率53.500% 昨日涨跌幅-1.290% 昨日净值1.6070元 起购金额100元 立即申购 高风险高收益
13 : 银河行业股票 近一年收益率44.340% 昨日涨跌幅-2.755% 昨日净值2.2940元 起购金额1000元 立即申购 高风险高收益
14 : 广发纯债债券A 近一年收益率20.820% 昨日涨跌幅-0.175% 昨日净值1.1410元 起购金额1000元 立即申购 高风险高收益
15 : 鹏华纯债债券 近一年收益率18.380% 昨日涨跌幅-0.089% 昨日净值1.1200元 起购金额1000元 立即申购 高风险高收益
16 : 宝盈核心优势混合 近一年收益率71.730% 昨日涨跌幅-1.261% 昨日净值1.4872元 起购金额1000元 立即申购 高风险高收益

通知手机

参考前面的用Telegram和树莓派交互 可以将变化通知到手机上的Telegram App。

<?php

exec('node wacai.js', $output);

$file = "wacai_last";

$last = @file_get_contents($file);

$funds = array();
foreach ($output as $i=>$line) {
	if (empty($line)) {
		continue;
	}
	if (strpos($line, "立即申购 本息保障") !== false) {
		$arr = explode(" ", $line);
		if ($arr[2] == "新手专享") {
			continue;
		}
		$fund = array(
			'index'=>$i,
			'name'=>$arr[2],
			'ratio'=>$arr[4],
			'days'=>$arr[8],
		);
		$funds[] = $fund;
	} else {
	}
}

$all = json_encode($funds,JSON_UNESCAPED_UNICODE);

if ($last != $all) {
	foreach ($funds as $fund) {
		$msg =  $output[$fund['index']];
		exec("echo 'msg 树莓派通知 $msg' | nc localhost 17777");
	}
	file_put_contents($file, $all);
}

参考链接

  1. https://www.npmjs.com/package/phantom


blog comments powered by Disqus

Published

2015-03-07

Categories


Tags