Skip to content

Commit

Permalink
add a more robust you say
Browse files Browse the repository at this point in the history
  • Loading branch information
lyle committed Dec 13, 2013
1 parent 4ec8f2e commit f948719
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 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('<form>your name:<input name="fromName"><br />message:<input name="say"><input type="submit"></form>Listen!<br/>' + messages.join('<br/>'));


}).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())

0 comments on commit f948719

Please sign in to comment.