-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodered-flow2.json
1 lines (1 loc) · 2.9 KB
/
nodered-flow2.json
1
[{"id":"879db9ad.997328","type":"inject","z":"ae6a6f57.e154b","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":172,"y":111,"wires":[["d0713c66.d0762"]]},{"id":"d0713c66.d0762","type":"function","z":"ae6a6f57.e154b","name":"construct dates and file.txt urls","func":"var daysPerMonth = [0,31,28,31,30,31,30,31,31,30,31,30,31];\nvar firstMonth = 2;\nvar firstDay = 21;\nvar year = 2017;\n\nvar today = new Date();\nvar currentDay = today.getDate();\nvar currentMonth = today.getMonth() + 1;\n\nvar dates = [];\nvar d = firstDay;\nfor (var m = firstMonth; m <= currentMonth; ) {\n dates.push(d++ + \"_\" + m + \"_\" + year);\n if ((m === currentMonth) && (d === currentDay)) {\n break;\n }\n if (d > daysPerMonth[m]) {\n d = 1;\n m++;\n }\n}\n\nvar urlList = [];\ndates.forEach(function(date) {\n urlList.push('http://collector.ita-ce.com/img/' + date + \"/files.txt\");\n});\n\nmsg.payload = urlList;\n\nurlList.some(function(el) {\n node.send({url: el});\n return true;\n});\n\n//msg.url = urlList[0];\n//return msg;","outputs":1,"noerr":0,"x":284,"y":176,"wires":[["9704ab25.2220d8"]]},{"id":"a4c6cccc.43b12","type":"cloudant out","z":"ae6a6f57.e154b","name":"","cloudant":"your-cloudant-id","database":"collected_images","service":"your-cloudant-service-name","payonly":true,"operation":"insert","x":1058,"y":257,"wires":[]},{"id":"9704ab25.2220d8","type":"http request","z":"ae6a6f57.e154b","name":"","method":"GET","ret":"txt","url":"","tls":"","x":554,"y":175,"wires":[["cabc0dd0.2c9e9"]]},{"id":"cabc0dd0.2c9e9","type":"function","z":"ae6a6f57.e154b","name":"extract image urls","func":"var images = msg.payload.split('\\n');\nvar counter = 0;\nvar imageModToPick = 0;\n\nimages = images.filter(function(el) {\n var el_stem = el.split('.');\n if (el_stem[el_stem.length-1] !== \"jpg\") {\n return false;\n }\n if (counter % 20 === imageModToPick) {\n counter++;\n return true;\n }\n counter++;\n return false;\n});\n\nnode.warn(images.length);\n\nimages.forEach(function(el) {\n elSplit = el.split('/');\n var imageJSON = {\n \"url\": \"http://collector.ita-ce.com/img/\" + elSplit[2] + \"/\" + elSplit[3] + \"/\" + elSplit[4] + \"/\" + elSplit[5],\n \"camera_id\": elSplit[5].slice(0,-4),\n \"date\": elSplit[2],\n \"hour\": elSplit[3],\n \"timestamp\": elSplit[4]\n };\n node.send({payload: imageJSON});\n});\n","outputs":1,"noerr":0,"x":751,"y":167,"wires":[["8acf9126.ae43"]]},{"id":"8acf9126.ae43","type":"delay","z":"ae6a6f57.e154b","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"10","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":982,"y":171,"wires":[["a4c6cccc.43b12"]]},{"id":"f7f40e4a.8943c","type":"cloudant","z":"","host":"your-cloudant-url","name":"annotation-cloudant"}]