/
markov-bot.js
35 lines (31 loc) · 997 Bytes
/
markov-bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var fs = require('fs');
var rita = require('rita');
var TwitterAPI = require('node-twitter-api');
// create markov model
var text = fs.readFileSync("genesis.txt", 'utf8');
var markov = rita.RiMarkov(3);
markov.loadText(text);
// grab keys from the command-line; see notes for instructions on how
// to obtain keys!
var cKey = process.argv[2];
var cSecret = process.argv[3];
var accessToken = process.argv[4];
var tokenSecret = process.argv[5];
// create a twitter API object
var twitter = TwitterAPI({
consumerKey: cKey,
consumerSecret: cSecret});
// post the status update. the value for the key "status" in the object below
// will be the content of the post.
twitter.statuses("update",
{"status": markov.generateSentences(1)[0]},
accessToken,
tokenSecret,
function(error, data, response) {
// code in this function will be executed after the request to post
// a status update.
if (error) {
console.log(error);
}
}
);