forked from dariusk/metaphor-a-minute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metaphor.js
141 lines (128 loc) · 3.69 KB
/
metaphor.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var restclient = require('node-restclient');
var Twit = require('twit');
var app = require('express').createServer();
// I deployed to Nodejitsu, which requires an application to respond to HTTP requests
// If you're running locally you don't need this, or express at all.
app.get('/', function(req, res){
res.send('Hello world.');
});
app.listen(3000);
// insert your twitter app info here
var T = new Twit({
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
});
var statement = "";
// insert your Wordnik API info below
var getNounsURL = "http://api.wordnik.com/v4/words.json/randomWords?" +
"minCorpusCount=1000&minDictionaryCount=10&" +
"excludePartOfSpeech=proper-noun,proper-noun-plural,proper-noun-posessive,suffix,family-name,idiom,affix&" +
"hasDictionaryDef=true&includePartOfSpeech=noun&limit=2&maxLength=12&" +
"api_key=______YOUR_API_KEY_HERE___________";
var getAdjsURL = "http://api.wordnik.com/v4/words.json/randomWords?" +
"hasDictionaryDef=true&includePartOfSpeech=adjective&limit=2&" +
"minCorpusCount=100&api_key=______YOUR_API_KEY_HERE___________";
function makeMetaphor() {
statement = "";
restclient.get(getNounsURL,
function(data) {
first = data[0].word.substr(0,1);
first2 = data[1].word.substr(0,1);
article = "a";
if (first === 'a' ||
first === 'e' ||
first === 'i' ||
first === 'o' ||
first === 'u') {
article = "an";
}
article2 = "a";
if (first2 === 'a' ||
first2 === 'e' ||
first2 === 'i' ||
first2 === 'o' ||
first2 === 'u') {
article2 = "an";
}
var connector = "is";
switch (Math.floor(Math.random()*12)) {
case 0:
connector = "of";
break;
case 1:
connector = "is";
break;
case 2:
connector = "is";
break;
case 3:
connector = "considers";
break;
case 4:
connector = "is";
break;
}
statement += article + " " + data[0].word + " " + connector + " " + article2 + " " + data[1].word;
restclient.get(
getAdjsURL,
function(data) {
var connector = " and";
switch (Math.floor(Math.random()*8)) {
case 0:
connector = ", not";
break;
case 1:
connector = ", yet";
break;
case 2:
connector = " but";
break;
case 3:
connector = ",";
break;
case 4:
connector = ", but not";
break;
}
output = data[0].word + connector + " " + data[1].word;
statement = statement + ": " + output;
console.log(statement);
T.post('statuses/update', { status: statement}, function(err, reply) {
console.log("error: " + err);
console.log("reply: " + reply);
});
}
,"json");
}
,"json");
}
function favRTs () {
T.get('statuses/retweets_of_me', {}, function (e,r) {
for(var i=0;i<r.length;i++) {
T.post('favorites/create/'+r[i].id_str,{},function(){});
}
console.log('harvested some RTs');
});
}
// every 2 minutes, make and tweet a metaphor
// wrapped in a try/catch in case Twitter is unresponsive, don't really care about error
// handling. it just won't tweet.
setInterval(function() {
try {
makeMetaphor();
}
catch (e) {
console.log(e);
}
},120000);
// every 5 hours, check for people who have RTed a metaphor, and favorite that metaphor
setInterval(function() {
try {
favRTs();
}
catch (e) {
console.log(e);
}
},60000*60*5);