From f9487193c4df26b05eeb72263c42683f8695a627 Mon Sep 17 00:00:00 2001 From: Lyle Troxell Date: Fri, 13 Dec 2013 09:59:26 -0800 Subject: [PATCH] add a more robust you say --- 008b_yousay.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 008b_yousay.js diff --git a/008b_yousay.js b/008b_yousay.js new file mode 100644 index 0000000..252959a --- /dev/null +++ b/008b_yousay.js @@ -0,0 +1,44 @@ +var http = require('http'); +var url = require('url') +var qs = require('querystring') +var exec = require('child_process').exec +var os = require('os') + +var messages = []; + +http.createServer(function (req, res) { + var daQuery, fromPerson, toSay; + res.writeHead(200, {'Content-Type': 'text/html'}); + + daQuery = qs.parse(url.parse(req.url).query) + if(daQuery["say"]){ + toSay = daQuery["say"].replace(/[\W\s\.-\?\!]/g,' ') + } + if(daQuery["fromName"]){ + fromPerson = daQuery["fromName"].replace(/[\W\s\.-\?\!]/g,' ') + } + + console.log(fromPerson + " said:" + toSay) + messages.push(fromPerson + " said:" + toSay) + + req.on('end',function(){ + if(toSay){ + if(fromPerson){ + exec('say -v "Kathy" ' + fromPerson + ' said ', function() + { + exec('say "' + toSay +'"') + }) + }else{ + exec('say "' + toSay +'"') + } + } + }) + res.end('
your name:
message:
Listen!
' + messages.join('
')); + + +}).listen(1337, '0.0.0.0'); + +console.log('Server running at http://127.0.0.1:1337/'); +console.log("Just visit with ...:1337/?say=Your Message Here") + +console.log(os.networkInterfaces()) \ No newline at end of file