今明36小時天氣預報
https://opendata.cwb.gov.tw/dataset/forecast/F-C0032-001
GET URL
https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/F-C0032-001?Authorization=CWB-05C514C3-55CB-4E40-978B-171E440D6B9C&downloadType=WEB&format=XML
Format : XML
//=========================================================Listlocation :
//var rawdata=context.global.temp;
global.set("tempera",msg.payload); //global.set
var rawdata = global.get("tempera");
//flow.set("loname",rawdata.cwbopendata.dataset[0].location.locationName);
var location=rawdata.cwbopendata.dataset[0].location;
var citynumber=location.length;
var cityarray=[];
var i;
for (i=0; i<citynumber;i++)
{
cityarray[i]=location[i].locationName[0];
}
msg.payload=cityarray;
flow.set("loname",cityarray);
return msg;
//=========================================================
//context.global.locationnumber=0;
//var rawdata=context.global.temp;
global.set("tempera",msg.payload); //global.set
var rawdata = global.get("tempera");
//flow.set("loname",rawdata.cwbopendata.dataset[0].location.locationName);
var location=rawdata.cwbopendata.dataset[0].location;
var loc=flow.get("locationnumber",3); //臺中
var locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];
var period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];
var period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];
var period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].startTime[0];
var period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].endTime[0];
var starthourtemp= period0start.split("T");
var starthour=starthourtemp[1].split(":")[0];
var endhourtemp= period0end.split("T");
var endhour=endhourtemp[1].split(":")[0];
var status1=locationName+starthour+"到"+endhour+"點 , 溫度最低"+period0min+"度最高"+period0max+"度";
//msg.payload=locationName+starthour+"到"+endhour+"點溫度最低"+period0min+"度最高"+period0max+"度";
msg.payload=status1;
return msg;
//=====================================================
//context.global.locationnumber=0;
//var rawdata=context.global.temp;
global.set("tempera",msg.payload); //global.set
var rawdata = global.get("tempera");
//flow.set("loname",rawdata.cwbopendata.dataset[0].location.locationName);
var location=rawdata.cwbopendata.dataset[0].location;
var loc=flow.get("locationnumber",3); //臺中
var period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];
var period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];
msg.payload=period0max;
return msg;
//=====================================================
//context.global.locationnumber=0;
//var rawdata=context.global.temp;
global.set("tempera",msg.payload); //global.set
var rawdata = global.get("tempera");
//flow.set("loname",rawdata.cwbopendata.dataset[0].location.locationName);
var location=rawdata.cwbopendata.dataset[0].location;
var loc=flow.get("locationnumber",3); //臺中
var period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];
var period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];
msg.payload=period0min;
return msg;
//=====================================================
//context.global.locationnumber=0;
//var rawdata=context.global.temp;
global.set("tempera",msg.payload); //global.set
var rawdata = global.get("tempera");
//flow.set("loname",rawdata.cwbopendata.dataset[0].location.locationName);
var location=rawdata.cwbopendata.dataset[0].location;
var loc=flow.get("locationnumber",3); //臺中
var locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];
var period0status=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[0].time[0].parameter[0].parameterName[0];
var period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[0].time[0].startTime[0];
var period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[0].time[0].endTime[0];
var starthourtemp= period0start.split("T");
var starthour=starthourtemp[1].split(":")[0];
var endhourtemp= period0end.split("T");
var endhour=endhourtemp[1].split(":")[0];
var status2 = locationName+starthour+"到"+endhour+"點 , 天氣狀況: "+period0status;
msg.payload=status2;
return msg;
[{"id":"e8ed80b3.a0afb","type":"http request","z":"c1b84172.51787","name":"temp request","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/F-C0032-001?Authorization=CWB-05C514C3-55CB-4E40-978B-171E440D6B9C&downloadType=WEB&format=XML","tls":"","persist":false,"proxy":"","authType":"","x":270,"y":80,"wires":[["3db0b988.a1c666"]]},{"id":"3db0b988.a1c666","type":"xml","z":"c1b84172.51787","name":"","property":"payload","attr":"","chr":"","x":410,"y":80,"wires":[["1c37b658.36caca","4db20add.e91c34","ccd207d6.87da38","eae9be49.b979a","9962f1bd.0013c","f160f17c.c98db"]]},{"id":"7243489f.6a8558","type":"ui_button","z":"c1b84172.51787","name":"","group":"1cc27a89.bee075","order":2,"width":"0","height":"0","passthru":false,"label":"取得台中市天氣","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":100,"y":140,"wires":[["e8ed80b3.a0afb","acede0e6.1a15d"]]},{"id":"8d3a0244.877ab","type":"inject","z":"c1b84172.51787","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":116,"y":68,"wires":[["e8ed80b3.a0afb"]]},{"id":"1c37b658.36caca","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":20,"wires":[]},{"id":"4db20add.e91c34","type":"function","z":"c1b84172.51787","name":"List locationname","func":"//var rawdata=context.global.temp;\nglobal.set(\"tempera\",msg.payload); //global.set\nvar rawdata = global.get(\"tempera\");\n//flow.set(\"loname\",rawdata.cwbopendata.dataset[0].location.locationName);\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar citynumber=location.length;\nvar cityarray=[];\nvar i;\nfor (i=0; i<citynumber;i++)\n{\ncityarray[i]=location[i].locationName[0];\n}\n\n msg.payload=cityarray;\nflow.set(\"loname\",cityarray);\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":60,"wires":[["cc762362.1472f"]]},{"id":"cc762362.1472f","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":40,"wires":[]},{"id":"ccd207d6.87da38","type":"function","z":"c1b84172.51787","name":"report","func":"//context.global.locationnumber=0;\n//var rawdata=context.global.temp;\nglobal.set(\"tempera\",msg.payload); //global.set\nvar rawdata = global.get(\"tempera\");\n//flow.set(\"loname\",rawdata.cwbopendata.dataset[0].location.locationName);\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar loc=flow.get(\"locationnumber\",3); //臺中\n\n\nvar locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];\nvar period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];\nvar period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];\nvar period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].startTime[0];\nvar period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].endTime[0];\n\nvar starthourtemp= period0start.split(\"T\");\nvar starthour=starthourtemp[1].split(\":\")[0];\nvar endhourtemp= period0end.split(\"T\");\nvar endhour=endhourtemp[1].split(\":\")[0];\nvar status1=locationName+starthour+\"到\"+endhour+\"點 , 溫度最低\"+period0min+\"度最高\"+period0max+\"度\";\n//msg.payload=locationName+starthour+\"到\"+endhour+\"點溫度最低\"+period0min+\"度最高\"+period0max+\"度\";\nmsg.payload=status1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":120,"wires":[["b0d74e47.1b0c6","a92ba76.fb9fc58"]]},{"id":"b0d74e47.1b0c6","type":"ui_text","z":"c1b84172.51787","group":"1cc27a89.bee075","order":0,"width":"8","height":"3","name":"","label":"","format":"{{msg.payload}}","layout":"col-center","x":790,"y":140,"wires":[]},{"id":"a92ba76.fb9fc58","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":745,"y":100,"wires":[]},{"id":"acede0e6.1a15d","type":"function","z":"c1b84172.51787","name":"","func":"msg.payload=' ';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":200,"wires":[["b0d74e47.1b0c6","4bc34091.be7b5","84ad41ed.d8693","4a7a499d.a293c8"]]},{"id":"4bc34091.be7b5","type":"ui_text","z":"c1b84172.51787","group":"1cc27a89.bee075","order":0,"width":"8","height":"3","name":"","label":"","format":"{{msg.payload}}","layout":"col-center","x":790,"y":280,"wires":[]},{"id":"eae9be49.b979a","type":"function","z":"c1b84172.51787","name":"report","func":"//context.global.locationnumber=0;\n//var rawdata=context.global.temp;\nglobal.set(\"tempera\",msg.payload); //global.set\nvar rawdata = global.get(\"tempera\");\n//flow.set(\"loname\",rawdata.cwbopendata.dataset[0].location.locationName);\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar loc=flow.get(\"locationnumber\",3); //臺中\n\n\nvar locationName=rawdata.cwbopendata.dataset[0].location[loc].locationName[0];\nvar period0status=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[0].time[0].parameter[0].parameterName[0];\nvar period0start=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[0].time[0].startTime[0];\nvar period0end=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[0].time[0].endTime[0];\n\nvar starthourtemp= period0start.split(\"T\");\nvar starthour=starthourtemp[1].split(\":\")[0];\nvar endhourtemp= period0end.split(\"T\");\nvar endhour=endhourtemp[1].split(\":\")[0];\n\nvar status2 = locationName+starthour+\"到\"+endhour+\"點 , 天氣狀況: \"+period0status;\nmsg.payload=status2;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":320,"wires":[["4bc34091.be7b5","8ca19f33.836f3"]]},{"id":"8ca19f33.836f3","type":"debug","z":"c1b84172.51787","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":340,"wires":[]},{"id":"84ad41ed.d8693","type":"ui_gauge","z":"c1b84172.51787","name":"","group":"1cc27a89.bee075","order":3,"width":"4","height":"4","gtype":"gage","title":"最高溫度","label":"units","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"28","seg2":"38","x":800,"y":180,"wires":[]},{"id":"4a7a499d.a293c8","type":"ui_gauge","z":"c1b84172.51787","name":"","group":"1cc27a89.bee075","order":62,"width":"4","height":"4","gtype":"gage","title":"最低溫度","label":"units","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"28","seg2":"38","x":800,"y":220,"wires":[]},{"id":"9962f1bd.0013c","type":"function","z":"c1b84172.51787","name":"","func":"//context.global.locationnumber=0;\n//var rawdata=context.global.temp;\nglobal.set(\"tempera\",msg.payload); //global.set\nvar rawdata = global.get(\"tempera\");\n//flow.set(\"loname\",rawdata.cwbopendata.dataset[0].location.locationName);\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar loc=flow.get(\"locationnumber\",3); //臺中\nvar period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];\nvar period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];\n\nmsg.payload=period0max;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":160,"wires":[["84ad41ed.d8693"]]},{"id":"f160f17c.c98db","type":"function","z":"c1b84172.51787","name":"","func":"//context.global.locationnumber=0;\n//var rawdata=context.global.temp;\nglobal.set(\"tempera\",msg.payload); //global.set\nvar rawdata = global.get(\"tempera\");\n//flow.set(\"loname\",rawdata.cwbopendata.dataset[0].location.locationName);\nvar location=rawdata.cwbopendata.dataset[0].location;\nvar loc=flow.get(\"locationnumber\",3); //臺中\nvar period0max=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[1].time[0].parameter[0].parameterName[0];\nvar period0min=rawdata.cwbopendata.dataset[0].location[loc].weatherElement[2].time[0].parameter[0].parameterName[0];\n\nmsg.payload=period0min;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":260,"wires":[["4a7a499d.a293c8"]]},{"id":"1cc27a89.bee075","type":"ui_group","z":"","name":"Info","tab":"2e8eb9a2.9f45f6","order":1,"disp":true,"width":"24","collapse":false},{"id":"2e8eb9a2.9f45f6","type":"ui_tab","z":"","name":"Weather","icon":"Dashboard","disabled":false,"hidden":false}]
沒有留言:
張貼留言