Skip to content

Commit

Permalink
refactor folders and add bots code
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Nov 15, 2015
1 parent 9337895 commit 6f7cb1f
Show file tree
Hide file tree
Showing 301 changed files with 327 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
config.js
node_modules
2 changes: 2 additions & 0 deletions code_bots/node1/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

console.log("Hello aribitrary video website");
20 changes: 20 additions & 0 deletions code_bots/node2/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
console.log('The bot is starting');

var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);

var params = {
q: 'rainbow',
count: 2
}

T.get('search/tweets', params, gotData);

function gotData(err, data, response) {
var tweets = data.statuses;
for (var i = 0; i < tweets.length; i++) {
console.log(tweets[i].text);
}
}
12 changes: 12 additions & 0 deletions code_bots/node2/config-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Change this file to config.js
// Add your keys
// Add file .gitignore: config.js
// Load with
// var config = require('./config.js');

module.exports = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
19 changes: 19 additions & 0 deletions code_bots/node2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "npm_demo",
"version": "1.0.0",
"description": "I am demonstrating npm.",
"main": "bot.js",
"scripts": {
"start": "node bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"rainbow",
"awkward"
],
"author": "",
"license": "ISC",
"dependencies": {
"twit": "^2.1.1"
}
}
21 changes: 21 additions & 0 deletions code_bots/node3/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
console.log('The bot is starting');

var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);


var tweet = {
status: '#codingrainbow from node.js'
}

T.post('statuses/update', tweet, tweeted);

function tweeted(err, data, response) {
if (err) {
console.log("Something went wwrong!");
} else {
console.log("It worked!");
}
}
12 changes: 12 additions & 0 deletions code_bots/node3/config-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Change this file to config.js
// Add your keys
// Add file .gitignore: config.js
// Load with
// var config = require('./config.js');

module.exports = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
19 changes: 19 additions & 0 deletions code_bots/node3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "npm_demo",
"version": "1.0.0",
"description": "I am demonstrating npm.",
"main": "bot.js",
"scripts": {
"start": "node bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"rainbow",
"awkward"
],
"author": "",
"license": "ISC",
"dependencies": {
"twit": "^2.1.1"
}
}
28 changes: 28 additions & 0 deletions code_bots/node4_a_setInterval/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
console.log('The bot is starting');

var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);

tweetIt();
setInterval(tweetIt, 1000*20);

function tweetIt() {

var r = Math.floor(Math.random()*100);

var tweet = {
status: 'random number ' + r + ' #codingrainbow'
}

T.post('statuses/update', tweet, tweeted);

function tweeted(err, data, response) {
if (err) {
console.log("Something went wwrong!");
} else {
console.log("It worked!");
}
}
}
12 changes: 12 additions & 0 deletions code_bots/node4_a_setInterval/config-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Change this file to config.js
// Add your keys
// Add file .gitignore: config.js
// Load with
// var config = require('./config.js');

module.exports = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
19 changes: 19 additions & 0 deletions code_bots/node4_a_setInterval/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "npm_demo",
"version": "1.0.0",
"description": "I am demonstrating npm.",
"main": "bot.js",
"scripts": {
"start": "node bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"rainbow",
"awkward"
],
"author": "",
"license": "ISC",
"dependencies": {
"twit": "^2.1.1"
}
}
37 changes: 37 additions & 0 deletions code_bots/node4_b_followbot/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
console.log('The follow bot is starting');

var Twit = require('twit');

var config = require('./config');
var T = new Twit(config);

// Setting up a user stream
var stream = T.stream('user');

// Anytime someone follows me
stream.on('follow', followed);

function followed(eventMsg) {
console.log("Follow event!");
var name = eventMsg.source.name;
var screenName = eventMsg.source.screen_name;
tweetIt('.@' + screenName + ' do you like rainbows?');
}


function tweetIt(txt) {

var tweet = {
status: txt
}

T.post('statuses/update', tweet, tweeted);

function tweeted(err, data, response) {
if (err) {
console.log("Something went wwrong!");
} else {
console.log("It worked!");
}
}
}
12 changes: 12 additions & 0 deletions code_bots/node4_b_followbot/config-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Change this file to config.js
// Add your keys
// Add file .gitignore: config.js
// Load with
// var config = require('./config.js');

module.exports = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
19 changes: 19 additions & 0 deletions code_bots/node4_b_followbot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "npm_demo",
"version": "1.0.0",
"description": "I am demonstrating npm.",
"main": "bot.js",
"scripts": {
"start": "node bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"rainbow",
"awkward"
],
"author": "",
"license": "ISC",
"dependencies": {
"twit": "^2.1.1"
}
}
46 changes: 46 additions & 0 deletions code_bots/node5/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
console.log('The image bot is starting');

var Twit = require('twit');

var config = require('./config');

var T = new Twit(config);

var exec = require('child_process').exec;
var fs = require('fs');

tweetIt();
// setInterval(tweetIt, 1000*20);

function tweetIt() {
var cmd = 'processing-java --sketch=`pwd`/rainbow --run';
exec(cmd, processing);

function processing() {
var filename = 'rainbow/output.png';
var params = {
encoding: 'base64'
}
var b64 = fs.readFileSync(filename, params);

T.post('media/upload', { media_data: b64 }, uploaded);

function uploaded(err, data, response) {
var id = data.media_id_string;
var tweet = {
status: '#codingrainbow live from node.js',
media_ids: [id]
}
T.post('statuses/update', tweet, tweeted);

}

function tweeted(err, data, response) {
if (err) {
console.log("Something went wwrong!");
} else {
console.log("It worked!");
}
}
}
}
12 changes: 12 additions & 0 deletions code_bots/node5/config-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Change this file to config.js
// Add your keys
// Add file .gitignore: config.js
// Load with
// var config = require('./config.js');

module.exports = {
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
}
19 changes: 19 additions & 0 deletions code_bots/node5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "npm_demo",
"version": "1.0.0",
"description": "I am demonstrating npm.",
"main": "bot.js",
"scripts": {
"start": "node bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"rainbow",
"awkward"
],
"author": "",
"license": "ISC",
"dependencies": {
"twit": "^2.1.1"
}
}
Binary file added code_bots/node5/rainbow/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions code_bots/node5/rainbow/rainbow.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

void setup() {
size(640, 360);
background(51);
for (int i = 0; i < 5000; i++) {
float x = random(width);
float y = random(height);
float r = random(100, 255);
float b = random(100, 255);
noStroke();
fill(r, 0, b, 100);
ellipse(x, y, 16, 16);
}
save("output.png");
exit();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6f7cb1f

Please sign in to comment.