-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweets.js
39 lines (34 loc) · 980 Bytes
/
tweets.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
// Given an array of sentence strings, findHaiku() looks for
// and returns a string that matches haiku grammar, if one exists.
function findHaiku(data, query, cb) {
var tweets = JSON.parse(data).statuses
var numTweets = tweets.length
var foundHaiku = false
var i = 0
// for (var i = 0; i <= count - 1; i++) {
while (foundHaiku == false) {
if (i >= numTweets) {
console.log('--possible re-poll oportunity--')
cb({ "line1": "Could not find haiku...", "line2": "", "line3": "" })
break
}
str = tweets[i].text
haiku(str, function (err, data) {
if (err) {
console.error('Error! '.red, err)
i++
}
else {
console.log('Found haiku GOOD'.green)
data.url = "http://twitter.com/" + tweets[i].user.screen_name + "/status/" + tweets[i].id_str
console.log(data)
data['q'] = query
cb(data)
foundHaiku = true
}
})
}
}
module.exports = {
findHaiku
}