forked from CDSLab/CodeCamp2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeather
2 lines (1 loc) · 4.88 KB
/
Weather
1
2
[{"id":"7768c3ea.88973c","type":"function","z":"ddac6534.225398","name":"Format speech","func":"//console.log(\"The msg payload is : \" + JSON.stringify(msg));\nmsg.payload = \"Current weather in \"+msg.locationString+\" is \" + msg.observation.temp + \" degrees and \" + msg.observation.wx_phrase + \". \" + \nmsg.observation.terse_phrase;\nreturn msg;","outputs":1,"noerr":0,"x":849.5,"y":297,"wires":[["f8b4193f.074be8"]]},{"id":"4d872190.b278e","type":"weather_insights","z":"ddac6534.225398","name":"Current weather","service":"/observations.json","geocode":"","units":"e","language":"en-US","x":581.5,"y":330,"wires":[["7768c3ea.88973c"]]},{"id":"f8b4193f.074be8","type":"watson-text-to-speech","z":"ddac6534.225398","name":"","lang":"english","voice":"en-US_MichaelVoice","format":"audio/wav","x":679,"y":171,"wires":[["969babb9.696458"]]},{"id":"e917ddab.16e82","type":"switch","z":"ddac6534.225398","name":"Current or forecast","property":"transcription","propertyType":"msg","rules":[{"t":"cont","v":"current","vt":"str"},{"t":"cont","v":"forecast","vt":"str"},{"t":"else"}],"checkall":"true","outputs":3,"x":322,"y":296,"wires":[["4d872190.b278e"],["92e31ae.f6d1ce8"],["4d872190.b278e"]]},{"id":"969babb9.696458","type":"function","z":"ddac6534.225398","name":"Set headers","func":"// Set the content type to audio wave\nmsg.headers={ 'Content-Type': 'audio/wav'};\nmsg.payload = msg.speech;\nreturn msg;","outputs":1,"noerr":0,"x":821.5,"y":77,"wires":[["95fe05cc.6a01f8"]]},{"id":"4fc76e96.b0389","type":"function","z":"ddac6534.225398","name":"Format speech","func":"console.log(msg.forecasts);\nmsg.payload=\"Forecast for \" + msg.locationString + \": For the rest of today there will be \" + msg.forecasts[0].narrative +\n\" Tomorrow it will be \" + msg.forecasts[1].narrative;\nreturn msg;","outputs":1,"noerr":0,"x":874.5,"y":366,"wires":[["f8b4193f.074be8"]]},{"id":"92e31ae.f6d1ce8","type":"weather_insights","z":"ddac6534.225398","name":"Weather forecast","service":"/forecast/daily/10day.json","geocode":"37.20,-121.53","units":"e","language":"en-US","x":578.5,"y":404,"wires":[["f05f174a.0fa0e8","4fc76e96.b0389"]]},{"id":"d5741cc3.2a8be","type":"function","z":"ddac6534.225398","name":"lat & lon","func":"lat = msg.payload.results[0].geometry.location.lat;\nlon = msg.payload.results[0].geometry.location.lng;\nconsole.log(\"long is: \" + lon);\nmsg.location={'lat':lat,'lon':lon};\nreturn msg;","outputs":1,"noerr":0,"x":159.5,"y":231,"wires":[["4a724f66.b58db","e917ddab.16e82"]]},{"id":"95fe05cc.6a01f8","type":"http response","z":"ddac6534.225398","name":"","x":926,"y":160,"wires":[]},{"id":"f05f174a.0fa0e8","type":"debug","z":"ddac6534.225398","name":"","active":true,"console":"false","complete":"forecasts","x":823.5,"y":443,"wires":[]},{"id":"2be709ef.d418f6","type":"http request","z":"ddac6534.225398","name":"","method":"GET","ret":"txt","url":"","tls":"","x":168,"y":147,"wires":[["8f784498.ac1248","e0d2cd9c.03f53"]]},{"id":"4a724f66.b58db","type":"debug","z":"ddac6534.225398","name":"","active":true,"console":"false","complete":"location","x":459.5,"y":244,"wires":[]},{"id":"92915d7c.6d6ea","type":"function","z":"ddac6534.225398","name":"Construct URL","func":"if (msg.transcription.indexOf('in') > -1) \n {\n msg.locationString = msg.transcription.split('in ').pop();\n }\nelse if (msg.transcription.indexOf('for') > -1) \n {\n msg.locationString = msg.transcription.split('for ').pop();\n } \nmsg.encodedLocation = encodeURIComponent(msg.locationString);\nmsg.url='https://maps.googleapis.com/maps/api/geocode/json?address='+msg.encodedLocation+'&key=AIzaSyCjKV9cQpkKaua_qFJOMdJOfFG_FT_Bq9k'\nreturn msg;","outputs":1,"noerr":0,"x":264,"y":51,"wires":[["2be709ef.d418f6"]]},{"id":"bd743b37.428bc8","type":"link in","z":"ddac6534.225398","name":"Incoming weather","links":["331ac411.cce53c","344a1fa9.cbb5e"],"x":145,"y":37,"wires":[["92915d7c.6d6ea"]]},{"id":"94906940.6b6f98","type":"comment","z":"ddac6534.225398","name":"Google maps API","info":"","x":85,"y":103,"wires":[]},{"id":"8f784498.ac1248","type":"debug","z":"ddac6534.225398","name":"","active":true,"console":"true","complete":"true","x":314.5,"y":186,"wires":[]},{"id":"188c7885.34ba97","type":"switch","z":"ddac6534.225398","name":"Error check google API results","property":"payload.status","propertyType":"msg","rules":[{"t":"eq","v":"ZERO_RESULTS","vt":"str"},{"t":"else"}],"checkall":"true","outputs":2,"x":508.5,"y":74,"wires":[["4ef4107e.7869b"],["d5741cc3.2a8be"]]},{"id":"4ef4107e.7869b","type":"function","z":"ddac6534.225398","name":"No results found message","func":"msg.payload=\"I'm sorry, I cannot identify the location: \" + msg.locationString;\nreturn msg;","outputs":1,"noerr":0,"x":777.5,"y":37,"wires":[["f8b4193f.074be8"]]},{"id":"e0d2cd9c.03f53","type":"function","z":"ddac6534.225398","name":"Parse the JSON string ","func":"msg.payload=JSON.parse(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":353.5,"y":127,"wires":[["188c7885.34ba97"]]}]