工行纸黄金数据监测

需求

在工行纸黄金价格涨幅超过量点的情况下做推送提醒, 数据来源第一黄金网

如果你需要监测别的贵金属数据,在获取黄金价格节点更换相应的地址即可

节点效果图如下:

依赖节点

node-red-contrib-cheerio-function

详细流程如下

[{"id":"29019645.0bc48a","type":"tab","label":"纸金监控","disabled":false,"info":""},{"id":"9bdccf4e.a9b43","type":"inject","z":"29019645.0bc48a","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":113,"y":104.66662788391113,"wires":[["9dc4e93b.e360a8"]]},{"id":"9dc4e93b.e360a8","type":"http request","z":"29019645.0bc48a","name":"获取纸黄金价格","method":"GET","ret":"txt","url":"http://www.dyhjw.com/zhihuangjin","tls":"","x":374.83343505859375,"y":103.6666259765625,"wires":[["cc5c4249.6009a"]]},{"id":"6476fa75.ce20d4","type":"debug","z":"29019645.0bc48a","name":"调式信息","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":887,"y":235,"wires":[]},{"id":"8a69974.5b4ef68","type":"function","z":"29019645.0bc48a","name":"数据处理","func":"var payload = msg.payload;\n\n//如果是+0.28 这里会得到2.8\nvar swingRange = parseFloat(payload.swingRange) * 10\n//取整 2\nvar intSwingRange = parseInt(swingRange)\n//-2 等到2, 2也是等到2\nvar range = Math.abs(intSwingRange)\n//过滤小于2的涨幅\nif(range < 2) {\n    return null\n}\n\nmsg.data = payload\n//可以使用rbe做数据过滤,不变化不执行下面流出\nmsg.payload = intSwingRange\nmsg.data.date = new Date().toLocaleString()\nreturn msg;","outputs":1,"noerr":0,"x":372,"y":319,"wires":[["ada7ce41.74b28"]]},{"id":"ada7ce41.74b28","type":"rbe","z":"29019645.0bc48a","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":550,"y":316,"wires":[["350075a1.f2ee7a","6476fa75.ce20d4"]]},{"id":"350075a1.f2ee7a","type":"template","z":"29019645.0bc48a","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"现在黄金价格为: {{data.last}}  \n涨幅: {{data.swing}}  \n涨幅比: {{data.swingRange}}  \n提示时间: {{data.date}}  ","output":"str","x":735,"y":315,"wires":[["df02ece1.944d8"]]},{"id":"df02ece1.944d8","type":"pushbear","z":"29019645.0bc48a","server":"","title":"","content":"","x":904,"y":315,"wires":[[]]},{"id":"cc5c4249.6009a","type":"cheerio-function","z":"29019645.0bc48a","name":"","func":"\n\nvar payload = {}\npayload.swing = $(\"font.swing\").text()\npayload.swingRange = $(\"font.swingRange\").text()\npayload.last = $(\".nom\").text()\n\n//swing\n//swingRange\n//last\nvar newMsg = {}\nnewMsg.payload = payload;\n\nreturn newMsg;","outputs":1,"noerr":0,"x":587,"y":101,"wires":[["8a69974.5b4ef68"]]}]