Skip to content

Instantly share code, notes, and snippets.

@PonDad
Created March 5, 2016 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PonDad/f954be622764b67067cc to your computer and use it in GitHub Desktop.
Save PonDad/f954be622764b67067cc to your computer and use it in GitHub Desktop.
Samuel L 9000 Raspberry Pi
var express = require('express');
var ejs = require("ejs");
var spawn = require('child_process').spawn;
var app = express();
app.engine('ejs',ejs.renderFile);
app.get('/', function(req, res){
res.render('control.ejs',
{title: 'Samuel L 9000'});
});
app.get('/samuel', function(req, res){
res.render('samuel.ejs',
{title: 'Samuel L 9000'});
});
app.get('/wakeup', function (req, res) {
var text = req.query.text;
console.log(req.query);
var cool_cmd = "espeak 'OK. Fuckin Cool.'";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(cool_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Say. Cool.' );
});
var wakeup_cmd = "URL='http://192.168.0.12:3000/samuel' startx";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(wakeup_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Wake Up.' );
});
});
app.get('/play', function (req, res) {
var text = req.query.text;
console.log(req.query);
var watch = "https://www.youtube.com/watch?v=57oBC_WLsYA";
var cool_cmd = "espeak 'Fuckin Cool Music Play!'";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(cool_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Clear. Music Play.' );
});
var play_cmd = "youtube-dl " + watch + " -o - | mplayer - -novideo";
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(play_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Mosic Exit.' );
});
});
app.get('/stop', function (req, res) {
var text = req.query.text;
console.log(req.query);
var cool_cmd = "killall mplayer";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(cool_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Music Stop.' );
});
});
app.get('/cheese', function (req, res) {
var text = req.query.text;
console.log(req.query);
var default_cmd = "espeak -p20 'A Royale with cheese! What do they call a Big Mac?'";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(default_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Say. Royal with cheese.' );
});
});
app.get('/bigmac', function (req, res) {
var text = req.query.text;
console.log(req.query);
var default_cmd = "espeak -p20 'Le Big-Mac! Hahaha! What do they call a Whopper?'";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(default_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Say. Royal with cheese.' );
});
});
app.get('/ezeikil', function (req, res) {
var text = req.query.text;
console.log(req.query);
var default_cmd = "espeak -p20 'Ezekiel 25:17.The path of the righteous man is beset on all sides .And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee.'";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(default_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'Say. Ezeikil 25.' );
});
});
app.get('/control', function (req, res) {
var text = req.query.text;
console.log(req.query);
var default_cmd = "espeak 'Mother Fucker.'";
//console.log("cmd = "+cmd);
function shspawn(command) {
return spawn('sh', ['-c', command]);
}
var child = shspawn(default_cmd);
var buf="";
child.stdout.on('data',function(data){
buf=buf+data;
});
child.stderr.on('data',function (data){
//console.log('exec error: '+data);
});
child.on('close',function(code) {
console.log( 'SAY. MOTHER FUCKER.' );
});
});
var server = app.listen(3000, function () {
var host = server.address().address
var port = server.address().port
console.log('This app listening at http://192.168.0.12:'+ port)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment