日幣匯率 ( Node-Red 爬蟲 + telegram )
由telegram 送出請求 例如 rate,0.23
到https://rate.bot.com.tw/xrt?Lang=zh-TW
取得日圓匯率回telegram
可以 日圓,0.24 或 美元32.5.....取得需要的匯率
Node-Red程式
[{"id":"639381b4.decba","type":"inject","z":"cfd0631de3fd81fd","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"str"}],"repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":120,"wires":[["63a4a95.925ad58"]]},{"id":"63a4a95.925ad58","type":"http request","z":"cfd0631de3fd81fd","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://rate.bot.com.tw/xrt?Lang=zh-TW","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":240,"y":120,"wires":[["38a8cc.2269c734"]]},{"id":"38a8cc.2269c734","type":"html","z":"cfd0631de3fd81fd","name":"filter","property":"payload","outproperty":"payload","tag":".rate-content-cash.text-right.print_hide","ret":"html","as":"single","x":370,"y":120,"wires":[["29ecf860.b24508","91e26219.6161e"]]},{"id":"29ecf860.b24508","type":"function","z":"cfd0631de3fd81fd","name":"Get 日圓匯率 1","func":"var currency = 0.20;\n\nvar data = {\n jpy: Number(msg.payload[15])\n}\n\nvar isLow = flow.get('isLow') || false;\nmsg.payload = data\nif (data.jpy < currency && !isLow) {\n isLow = true;\n flow.set('isLow', isLow);\n return msg;\n}\nif (data.jpy > currency && !isLow) {\n isLow = false;\n flow.set('isLow', isLow);\n return msg;\n}","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":180,"wires":[["a75c6b33ab13f151"]]},{"id":"1d418e6a.0e52a2","type":"debug","z":"cfd0631de3fd81fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":710,"y":100,"wires":[]},{"id":"91e26219.6161e","type":"function","z":"cfd0631de3fd81fd","name":"GET 日圓匯率 2","func":"//var jp = msg.payload[15];\nvar data = {\n jpy: Number(msg.payload[15])\n}\nvar date = new Date();\nmsg.payload = data\nvar h = date.getHours();\nvar m = date.getMinutes();\nvar s = date.getSeconds();\nif(h<10){\n h = '0'+h;\n}\nif(m<10){\n m = '0' + m;\n}\nif(s<10){\n s = '0' + s;\n}\n\n\nvar value = global.get(\"change\")\nif (data.jpy <= value)\n msg.payload = '(' + h + ':' + m + ':' + s + ')\\n'+\n '日幣匯率:' + data.jpy ;\nelse\n msg.payload = '高於設定匯率' +value ;\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":100,"wires":[["1d418e6a.0e52a2","7e4eb32d6c62197b"]]},{"id":"5d6f427ff737f39e","type":"telegram receiver","z":"cfd0631de3fd81fd","name":"牌告匯率","bot":"your_telegram_bot_config_id","saveDataDir":"","filterCommands":false,"x":80,"y":240,"wires":[["ceeeaef0c81e8a5b","bbfe8906520f8a75","5bf1075a988c511d","3d857d7966a8004b"],[]]},{"id":"085d340990cf180b","type":"telegram sender","z":"cfd0631de3fd81fd","name":"牌告匯率","bot":"your_telegram_bot_config_id","haserroroutput":true,"outputs":2,"x":860,"y":180,"wires":[[],[]]},{"id":"a75c6b33ab13f151","type":"debug","z":"cfd0631de3fd81fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":180,"wires":[]},{"id":"7e4eb32d6c62197b","type":"template","z":"cfd0631de3fd81fd","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"台灣銀行牌告匯率 今日{{payload}}\"}\n","output":"json","x":690,"y":140,"wires":[["085d340990cf180b"]]},{"id":"ceeeaef0c81e8a5b","type":"function","z":"cfd0631de3fd81fd","name":"function ","func":"if (msg.payload.content === 'rate') {\n return [[{ payload: true }, null]];\n} else {\n return [[null, { payload: false }]];\n}\n\n","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":260,"wires":[[],["93dd79e280c0f37c"]]},{"id":"bbfe8906520f8a75","type":"switch","z":"cfd0631de3fd81fd","name":"","property":"payload.content","propertyType":"msg","rules":[{"t":"cont","v":"rate","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":220,"wires":[["63a4a95.925ad58"],["cc913a5b4576f97b"]]},{"id":"5bf1075a988c511d","type":"function","z":"cfd0631de3fd81fd","name":"function ","func":"const parts = msg.payload.content.split(',');\nconst changeValue = parts[1];\nglobal.set(\"change\", changeValue);\nmsg.payload = [parts[0], changeValue]; // 為了方便後續流程,payload 也包含這兩個值\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":300,"wires":[[]]},{"id":"3d857d7966a8004b","type":"debug","z":"cfd0631de3fd81fd","name":"debug 350","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":250,"y":340,"wires":[]},{"id":"93dd79e280c0f37c","type":"debug","z":"cfd0631de3fd81fd","name":"debug 351","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":300,"wires":[]},{"id":"cc913a5b4576f97b","type":"template","z":"cfd0631de3fd81fd","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"輸入資料錯誤\"}\n","output":"json","x":690,"y":240,"wires":[["085d340990cf180b"]]},{"id":"your_telegram_bot_config_id","type":"telegram bot","botname":"@ncutedu_exchange_rate_bot","usernames":"","chatids":"7965218469","baseapiurl":"","testenvironment":false,"pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","botpath":"","localbothost":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]



沒有留言:
張貼留言