Node-red OPEN Data
CWB-40C25FFF-1224-4250-B9D9-3735AAE17DBF
https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/F-D0047-091?Authorization=CWB-40C25FFF-1224-4250-B9D9-3735AAE17DBF&downloadType=WEB&format=JSON
https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/F-C0032-001?Authorization=CWB-40C25FFF-1224-4250-B9D9-3735AAE17DBF&downloadType=WEB&format=JSON
flow.set("temp",msg.payload); var rawdata =
flow.get("temp");
var
citynumber=rawdata.records.length; var
cityarray=[]; var i; for (i=0;
i<citynumber;i++) { cityarray[i]=rawdata.records[i].sitename; }
msg.payload=cityarray; flow.set("locationname",cityarray); return msg; |
flow.set("temp",msg.payload); var rawdata = flow.get("temp");
var citynumber=rawdata.records.length; var site_array=[]; var aqi_array=[]; var pm25_array=[]; var i; for (i=0; i<citynumber;i++) {
site_array[i]=rawdata.records[i].sitename;
aqi_array[i]=rawdata.records[i].aqi;
pm25_array[i]=rawdata.records[i].pm25subindex; }
msg.payload={site_array,aqi_array,pm25_array}; flow.set("Loc",site_array); flow.set("Aqi",aqi_array); flow.set("PM25",pm25_array); return msg; |
var a = flow.get("RECORDS");
var number=a.length; var AQI,PM25,SITE; var i;
for (i=0; i<number;i++) { if
(a[i].sitename=="大里") {
SITE=a[i].sitename;
AQI=a[i].aqi;
PM25=a[i].pm25subindex;
msg.payload={SITE,AQI,PM25}; return
msg; } } |
會 找到最後一個 '大里'
var a = msg.payload; var PM252;
a.forEach (function(array,i) {
if(array.sitename =="大里") { PM252 =
' 站名 '+ array['sitename'] ; PM252 =
', 日期 '+ array['monitordate'] ; PM252 =
PM252 + ' , AQI=' + array['aqi'] ; PM252 =
PM252 + ' , CO=' + array['cosubindex']
; PM252 =
PM252 + ' , PM2.5 index=' +
array['pm25subindex'] ; } } ); msg.payload={PM252}; return msg;
//// array.forEach(function (value,index) { //// }); |
[{"id":"7457a2c38759ab83","type":"tab","label":"流程7","disabled":false,"info":"","env":[]},{"id":"db35eedd.0f98d","type":"inject","z":"7457a2c38759ab83","name":"","repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":140,"y":180,"wires":[["a01f1370.156cb"]]},{"id":"cad8a53e.7a4f68","type":"debug","z":"7457a2c38759ab83","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":530,"y":180,"wires":[]},{"id":"56ee8868.ef9858","type":"debug","z":"7457a2c38759ab83","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":440,"wires":[]},{"id":"fe77de89.2ef91","type":"function","z":"7457a2c38759ab83","name":"大里 PM2.5","func":"var a = flow.get(\"RECORDS\");\n\nvar number=a.length;\nvar AQI,PM25,SITE;\nvar i;\n\nfor (i=0; i<number;i++) {\n if (a[i].sitename==\"大里\") {\n SITE=a[i].sitename;\n AQI=a[i].aqi;\n PM25=a[i].pm25subindex;\n \n msg.payload={SITE,AQI,PM25};\n return msg;\n }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":440,"wires":[["56ee8868.ef9858"]]},{"id":"a01f1370.156cb","type":"http request","z":"7457a2c38759ab83","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://data.epa.gov.tw/api/v2/aqx_p_434?api_key=e8dd42e6-9b8b-43f8-991e-b3dee723a52d&limit=1000&sort=monitordate%20desc&format=JSON","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":320,"y":180,"wires":[["cad8a53e.7a4f68","c450972c2e82d2c1","28d7f9915b232602","bc3b32fe3ba5cbe5"]]},{"id":"26470ad.694ebf6","type":"function","z":"7457a2c38759ab83","name":"大里 PM2.5","func":"var a = msg.payload;\nvar PM252;\n\na.forEach (function(array,i)\n{\n if(array.sitename ==\"大里\") {\n PM252 = ' 站名 '+ array['sitename'] ; \n PM252 = ', 日期 '+ array['monitordate'] ; \n PM252 = PM252 + ' , AQI=' + array['aqi'] ;\n PM252 = PM252 + ' , CO=' + array['cosubindex'] ;\n PM252 = PM252 + ' , PM2.5 index=' + array['pm25subindex'] ;\n }\n } );\nmsg.payload={PM252};\nreturn msg;\n\n\n//// array.forEach(function (value,index) {\n//// });","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":500,"wires":[["98a55050.a0c4d"]]},{"id":"98a55050.a0c4d","type":"debug","z":"7457a2c38759ab83","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":500,"wires":[]},{"id":"c450972c2e82d2c1","type":"function","z":"7457a2c38759ab83","name":"function 2","func":"\nflow.set(\"temp\",msg.payload);\nvar rawdata = flow.get(\"temp\");\n\nvar citynumber=rawdata.records.length;\nvar cityarray=[];\nvar i;\nfor (i=0; i<citynumber;i++)\n{\n cityarray[i]=rawdata.records[i].sitename;\n}\n\nmsg.payload=cityarray;\nflow.set(\"locationname\",cityarray);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":240,"wires":[["901b6d6035b85cec"]]},{"id":"901b6d6035b85cec","type":"debug","z":"7457a2c38759ab83","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":710,"y":240,"wires":[]},{"id":"28d7f9915b232602","type":"function","z":"7457a2c38759ab83","name":"function 3","func":"\nflow.set(\"temp\",msg.payload);\nvar rawdata = flow.get(\"temp\");\n\nvar citynumber=rawdata.records.length;\nvar site_array=[];\nvar aqi_array=[];\nvar pm25_array=[];\nvar i;\nfor (i=0; i<citynumber;i++)\n{\n site_array[i]=rawdata.records[i].sitename;\n aqi_array[i]=rawdata.records[i].aqi;\n pm25_array[i]=rawdata.records[i].pm25subindex;\n \n}\n\nmsg.payload={site_array,aqi_array,pm25_array};\nflow.set(\"Loc\",site_array);\nflow.set(\"Aqi\",aqi_array);\nflow.set(\"PM25\",pm25_array);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":300,"wires":[["146a85a458086283"]]},{"id":"bc3b32fe3ba5cbe5","type":"function","z":"7457a2c38759ab83","name":"function 4","func":"\nflow.set(\"temp\",msg.payload);\nvar rawdata = flow.get(\"temp\");\n\nvar citynumber=rawdata.records.length;\nvar records_array=[];\nvar i;\nfor (i=0; i<citynumber;i++)\n{\n records_array[i]=rawdata.records[i]\n}\n\nmsg.payload=records_array;\nflow.set(\"RECORDS\",records_array);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":360,"wires":[["bf2a0cd34449586b","fe77de89.2ef91","26470ad.694ebf6"]]},{"id":"146a85a458086283","type":"debug","z":"7457a2c38759ab83","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":300,"wires":[]},{"id":"bf2a0cd34449586b","type":"debug","z":"7457a2c38759ab83","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":360,"wires":[]}]
/v1/rest/datastore/F-C0032-001 一般天氣預報-今明 36 小時天氣預報
沒有留言:
張貼留言