2022年9月30日 星期五

Node-Red 取得台中市天氣(等待約30秒以上)

    Node-Red 取得台中市天氣(等待約30秒以上)


     Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;


https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/F-D0047-091?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) {

//// });

 

 

 

flow.set("tempera",msg.payload);

var rawdata = flow.get("tempera");

 

var citynumber=rawdata.cwbopendata.dataset.locations.location.length;

var cityarray=[];

var i;

for (i=0; i<citynumber;i++)

{

    cityarray[i]=rawdata.cwbopendata.dataset.locations.location[i];

}

 

msg.payload=cityarray;

flow.set("loname",cityarray);

return msg;

 

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload='平均溫度='+Temp+'°C , 平均相對濕度='+Mois+'% , 天氣'+ Weat+ ' , 發佈時間' + Stime;

return msg;

 

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload= Mois;

return msg;

 

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload= Temp;

return msg;

 

 


Stime=rawdata[i].weatherElement[0].time[0].startTime;


2022/9/30 下午5:15:01node: d73f973e.ef0298msg.payload : Object

object

cwbopendata: object

@xmlns: "urn:cwb:gov:tw:cwbcommon:0.1"

identifier: "fb364e55-73cf-4c5f-a8a8-f98a25972dbf"

sender: "weather@cwb.gov.tw"

sent: "2022-09-30T16:52:51+08:00"

status: "Actual"

scope: "Public"

msgType: "Issue"

dataid: "D0047-091"

source: "MFC"

dataset: object

datasetInfo: object

locations: object

locationsName: "台灣"

location: array[22]

[0 … 9]

0: object

locationName: "連江縣"

geocode: "09007000"

lat: "26.154204"

lon: "119.929303"

weatherElement: array[15]

[0 … 9]

0: object

elementName: "T"

description: "平均溫度"

time: array[15]

[0 … 9]

0: object

startTime: "2022-09-30T18:00:00+08:00"

endTime: "2022-10-01T06:00:00+08:00"

elementValue: object

1: object

2: object

3: object

4: object

5: object

6: object

7: object

8: object

9: object

[10 … 14]

 

 


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) {

//// });

 

 

 

flow.set("tempera",msg.payload);

var rawdata = flow.get("tempera");

 

var citynumber=rawdata.cwbopendata.dataset.locations.location.length;

var cityarray=[];

var i;

for (i=0; i<citynumber;i++)

{

    cityarray[i]=rawdata.cwbopendata.dataset.locations.location[i];

}

 

msg.payload=cityarray;

flow.set("loname",cityarray);

return msg;

 

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload='平均溫度='+Temp+'°C , 平均相對濕度='+Mois+'% , 天氣'+ Weat+ ' , 發佈時間' + Stime;

return msg;

 

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload= Mois;

return msg;

 

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload= Temp;

return msg;

 

 

2022/9/30 下午5:15:01node: d73f973e.ef0298msg.payload : Object

object

cwbopendata: object

@xmlns: "urn:cwb:gov:tw:cwbcommon:0.1"

identifier: "fb364e55-73cf-4c5f-a8a8-f98a25972dbf"

sender: "weather@cwb.gov.tw"

sent: "2022-09-30T16:52:51+08:00"

status: "Actual"

scope: "Public"

msgType: "Issue"

dataid: "D0047-091"

source: "MFC"

dataset: object

datasetInfo: object

locations: object

locationsName: "台灣"

location: array[22]

[0 … 9]

0: object

locationName: "連江縣"

geocode: "09007000"

lat: "26.154204"

lon: "119.929303"

weatherElement: array[15]

[0 … 9]

0: object

elementName: "T"

description: "平均溫度"

time: array[15]

[0 … 9]

0: object

startTime: "2022-09-30T18:00:00+08:00"

endTime: "2022-10-01T06:00:00+08:00"

elementValue: object

1: object

2: object

3: object

4: object

5: object

6: object

7: object

8: object

9: object

[10 … 14]

 

 



 

flow.set("tempera",msg.payload);

var rawdata = flow.get("tempera");

 

var citynumber=rawdata.cwbopendata.dataset.locations.location.length;

var cityarray=[];

var i;

for (i=0; i<citynumber;i++)

{

    cityarray[i]=rawdata.cwbopendata.dataset.locations.location[i];

}

 

msg.payload=cityarray;

flow.set("loname",cityarray);

return msg;





 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload='平均溫度='+Temp+'°C , 平均相對濕度='+Mois+'% , 天氣'+ Weat+ ' , 發佈時間' + Stime;

return msg;

 

//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload= Mois;

return msg;


//flow.set("loname",cityarray);

 

var rawdata = flow.get("loname");

 

var citynumber=rawdata.length;

var i;

var Stime;

var Temp;

var Mois;

var Weat;

var dataDate;

 

for (i=0; i<citynumber;i++)

{

    if (rawdata[i].locationName==='臺中市')

    {

        Stime=rawdata[i].weatherElement[0].time[0].startTime;

        Temp=rawdata[i].weatherElement[0].time[0].elementValue.value;

        Mois=rawdata[i].weatherElement[2].time[2].elementValue.value;

        Weat=rawdata[i].weatherElement[12].time[2].elementValue[0].value;

        break;

    }

}

 

msg.payload= Temp;

return msg;

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...