-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalchemy-twitter-bot.js
78 lines (69 loc) · 2.44 KB
/
alchemy-twitter-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
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
var TwitterPackage = require('twitter');
var secret = require("./secret");
var Twitter = new TwitterPackage(secret);
var watson = require('watson-developer-cloud');
var jsonfile = require('jsonfile');
var watson_data = require('./data');
var file = 'data.json';
var alchemy_language = watson.alchemy_language({
api_key: '-----------------------'
});
var introArray = [
'Per your request: ',
'Current state of society is',
'Current state at',
'Here it is: ',
'As of right now: ',
'As requested: ',
'Analysis in at: ',
'Currently trending at: ',
'It is: ',
'The info you requested: ',
'Currently reading at: '
]
var randomIndex = Math.round(Math.random() * introArray.length);
var params = {
url: 'https://news.google.com',
/*'https://cbsnews.com',
'https://nbcnews.com/',
'https://abcnews.go.com/',
'https://foxnews.com/',
'https://bbc.com/news',
'https://cnn.com/'*/
};
Twitter.stream('statuses/filter', {track:'@botsight status'}, function(stream) {
stream.on('data', function(tweet) {
var tweetId = tweet.id;
console.log(tweet.text);
console.log(tweetId);
alchemy_language.emotion(params, function (err, response) {
var obj = response;
if (err)
console.log('error:', err);
else
jsonfile.writeFileSync(file, obj, {spaces: 1});
//console.log(JSON.stringify(response, null, 2));
});
var emotionalStateAnger = watson_data.docEmotions.anger;
var emotionalStateDisgust = watson_data.docEmotions.disgust;
var emotionalStateFear = watson_data.docEmotions.fear;
var emotionalStateJoy = watson_data.docEmotions.joy;
var emotionalStateSadness = watson_data.docEmotions.sadness;
var emotionalStates = emotionalStateAnger + emotionalStateDisgust + emotionalStateFear + emotionalStateJoy + emotionalStateSadness;
console.log(emotionalStates);
//in_reply_to_status_id: tweetId
var statusObj = {status: ' @' + tweet.user.screen_name + ' ' + introArray[randomIndex] + 'Anger: ' + emotionalStateAnger + ' Disgust: ' + emotionalStateDisgust + ' Fear: ' + emotionalStateFear + ' Joy: ' + emotionalStateJoy + ' Sadness: ' + emotionalStateSadness}
//call the post function to tweet something
Twitter.post('statuses/update', statusObj, function(error, tweetReply, response){
//if we get an error print it out
if(error){
console.log(error);
}
//print the text of the tweet we sent out
console.log(tweetReply.text);
});
});
stream.on('error', function(error) {
console.log(error);
});
});