2025年5月4日 星期日

使用 Node-RED 抓取匯率數值 + Telegram

 使用 Node-RED 抓取匯率數值 + Telegram 










[{"id":"8e4f17f64c69ef76","type":"inject","z":"3753d28b47d6e39d","name":"抓匯率","props":[],"repeat":"300","once":true,"onceDelay":"1","topic":"","payloadType":"date","x":260,"y":20,"wires":[["1aa15d604282cd10"]]},{"id":"1aa15d604282cd10","type":"http request","z":"3753d28b47d6e39d","name":"讀取 BOT 匯率網頁","method":"GET","ret":"txt","url":"https://rate.bot.com.tw/xrt?Lang=zh-TW","x":290,"y":100,"wires":[["8917d9854e5d06a2","0be09883b6749655","929d211b8ca5b62e"]]},{"id":"1d32b50d2cffdfb5","type":"ui_table","z":"3753d28b47d6e39d","group":"984f388c549c3daa","name":"匯率表","order":1,"width":10,"height":8,"columns":[],"outputs":0,"cts":false,"x":1090,"y":240,"wires":[]},{"id":"4879bba9387f8246","type":"debug","z":"3753d28b47d6e39d","name":"debug 360","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1030,"y":320,"wires":[]},{"id":"4d7e5d57650e373a","type":"inject","z":"3753d28b47d6e39d","name":"","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":260,"wires":[["1aa15d604282cd10"]]},{"id":"8917d9854e5d06a2","type":"html","z":"3753d28b47d6e39d","name":"擷取表格列","property":"payload","outproperty":"payload","tag":".rate-content-cash.text-right.print_hide","ret":"html","as":"single","chr":"","x":510,"y":100,"wires":[["7d93c868f73d1f34"]]},{"id":"0be09883b6749655","type":"html","z":"3753d28b47d6e39d","name":"擷取表格列","property":"payload","outproperty":"payload","tag":".rate-content-sight.text-right.print_hide","ret":"html","as":"single","chr":"","x":510,"y":200,"wires":[["5e3549d4d70440cc"]]},{"id":"27238557b6339db4","type":"debug","z":"3753d28b47d6e39d","name":"debug 362","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":200,"wires":[]},{"id":"7d93c868f73d1f34","type":"function","z":"3753d28b47d6e39d","name":"function 113","func":"flow.set('currency1',msg.payload);\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":100,"wires":[["2e114d36544fab94"]]},{"id":"2e114d36544fab94","type":"debug","z":"3753d28b47d6e39d","name":"debug 363","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":100,"wires":[]},{"id":"5e3549d4d70440cc","type":"function","z":"3753d28b47d6e39d","name":"function 114","func":"flow.set('currency2',msg.payload);\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":200,"wires":[["27238557b6339db4","ad16f6cbd1d9c6db"]]},{"id":"ad16f6cbd1d9c6db","type":"delay","z":"3753d28b47d6e39d","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":680,"y":260,"wires":[["59508d5b93c58fb3"]]},{"id":"929d211b8ca5b62e","type":"html","z":"3753d28b47d6e39d","name":"擷取表格列","property":"payload","outproperty":"payload","tag":".hidden-phone.print_show.xrt-cur-indent","ret":"html","as":"single","chr":"","x":510,"y":40,"wires":[["a0c6f0a4a9f2660f"]]},{"id":"d42e62cce26a1f3b","type":"debug","z":"3753d28b47d6e39d","name":"debug 365","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":20,"wires":[]},{"id":"a0c6f0a4a9f2660f","type":"function","z":"3753d28b47d6e39d","name":"function ","func":"let input = msg.payload; // 你的 HTML 編碼陣列\nlet result = input.map(str => {\n    // 抓出 () 之間的文字\n    let match = str.match(/\\(([^)]+)\\)/);\n    return match ? match[1] : null;\n});\n\nmsg.payload = result;\nflow.set('currency',msg.payload);\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":40,"wires":[["d42e62cce26a1f3b","7b0a273627e53c12"]]},{"id":"59508d5b93c58fb3","type":"function","z":"3753d28b47d6e39d","name":"function 115","func":"var codes = flow.get('currency');\nvar rates1 = flow.get('currency1');\nvar rates2 = flow.get('currency2');\n\n\n// 將幣別代碼從 \"美金 (USD)\" 取出英文代碼\ncodes = codes.map(str => {\n    let match = str.match(/\\(([^)]+)\\)/);\n    return match ? match[1] : str;\n});\n\nlet result = [];\n\nfor (let i = 0; i < codes.length; i++) {\n    result.push({\n        幣別: codes[i],\n        現金買入: rates1[i * 2] ?? \"-\",\n        現金賣出: rates1[i * 2 + 1] ?? \"-\",\n        即期買入: rates2[i * 2] ?? \"-\",\n        即期賣出: rates2[i * 2 + 1] ?? \"-\"\n    });\n}\n\nmsg.payload = result;\nflow.set('currency3',msg.payload);\nreturn msg;\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":320,"wires":[["4879bba9387f8246","1d32b50d2cffdfb5"]]},{"id":"c63e2aebc66bd943","type":"ui_dropdown","z":"3753d28b47d6e39d","name":"","label":"","tooltip":"","place":"Select option","group":"984f388c549c3daa","order":2,"width":3,"height":1,"passthru":true,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":1040,"y":60,"wires":[["27dad48e3975e27c","3e0b4a876cd2769c"]]},{"id":"7b0a273627e53c12","type":"change","z":"3753d28b47d6e39d","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":60,"wires":[["c63e2aebc66bd943"]]},{"id":"e0cd4229db164524","type":"template","z":"3753d28b47d6e39d","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n{\"chatId\": 7965218469,\n\"type\":\"message\",\n\"content\":\"台銀匯率 {{payload}}\"}\n","output":"json","x":1450,"y":240,"wires":[["8ea18338d6987fe2"]]},{"id":"8ea18338d6987fe2","type":"telegram sender","z":"3753d28b47d6e39d","name":"匯率","bot":"f99c60fa6cddd722","haserroroutput":true,"outputs":2,"x":1570,"y":240,"wires":[[],[]]},{"id":"3e0b4a876cd2769c","type":"function","z":"3753d28b47d6e39d","name":"function 116","func":"// 你要保留的幣別清單\nvar wantedCurrencies =  msg.payload;\n\n// 原始陣列資料,假設已在 msg.payload 中\nvar originalArray =flow.get('currency3');\n\n// 過濾符合的幣別\nconst filtered = originalArray.filter(item => wantedCurrencies.includes(item.幣別));\n\n// 將符合的資料存入 msg.payload.ma\nmsg.payload = {\n    ma: filtered\n};\n\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1190,"y":60,"wires":[["e6c3fb65970742ef","1d32b50d2cffdfb5","73578137e0a24c3d","b6849c8081c702a9"]]},{"id":"e6c3fb65970742ef","type":"debug","z":"3753d28b47d6e39d","name":"debug 366","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1350,"y":60,"wires":[]},{"id":"27dad48e3975e27c","type":"debug","z":"3753d28b47d6e39d","name":"debug 367","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":20,"wires":[]},{"id":"73578137e0a24c3d","type":"function","z":"3753d28b47d6e39d","name":"function 117","func":"\n// 讓 msg.payload 是一個原生 JS 物件,不需要轉字串\nmsg.payload = msg.payload.ma[0];  // 或整個 array\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1370,"y":120,"wires":[["611ffeebad1c44d9","e72613381da5c317"]]},{"id":"611ffeebad1c44d9","type":"debug","z":"3753d28b47d6e39d","name":"debug 368","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1570,"y":120,"wires":[]},{"id":"e72613381da5c317","type":"json","z":"3753d28b47d6e39d","name":"","property":"payload","action":"","pretty":true,"x":1510,"y":160,"wires":[["73ced88e33b0aa52"]]},{"id":"73ced88e33b0aa52","type":"debug","z":"3753d28b47d6e39d","name":"debug 369","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1650,"y":160,"wires":[]},{"id":"b6849c8081c702a9","type":"function","z":"3753d28b47d6e39d","name":"function 118","func":"// 將 JSON 物件轉為字串,並移除雙引號\nlet jsonString = JSON.stringify(msg.payload.ma[0], null, 2);\nmsg.payload = jsonString.replace(/\"/g, '');\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1310,"y":240,"wires":[["e0cd4229db164524"]]},{"id":"ab0f7958997a3333","type":"function","z":"3753d28b47d6e39d","name":"function 119","func":"msg.payload=msg.payload.content;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1090,"y":140,"wires":[["3e0b4a876cd2769c","82177e6abbba5369"]]},{"id":"82177e6abbba5369","type":"debug","z":"3753d28b47d6e39d","name":"debug 371","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1250,"y":160,"wires":[]},{"id":"c6dcbd6ba37ada01","type":"telegram receiver","z":"3753d28b47d6e39d","name":"匯率","bot":"f99c60fa6cddd722","saveDataDir":"","filterCommands":false,"x":870,"y":140,"wires":[["ab0f7958997a3333"],[]]},{"id":"984f388c549c3daa","type":"ui_group","name":"台銀","tab":"63ea0cbc9d1fb9a4","order":1,"disp":true,"width":10,"collapse":false,"className":""},{"id":"f99c60fa6cddd722","type":"telegram bot","botname":"@ncutedu_currency_bot","usernames":"","chatids":"","baseapiurl":"","testenvironment":false,"updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksprotocol":"socks5","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbothost":"0.0.0.0","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"63ea0cbc9d1fb9a4","type":"ui_tab","name":"匯率","icon":"dashboard","order":12,"disabled":false,"hidden":false}]

沒有留言:

張貼留言

8-QAM Signal 4 Phases 2 Amplitudes + 8PSK

 8-QAM Signal 4 Phases 2 Amplitudes + 8PSK import tkinter as tk from tkinter import messagebox import math import cmath # --- 8-QAM 參數設定 ---...