-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattweet.js
More file actions
59 lines (50 loc) · 1.56 KB
/
attweet.js
File metadata and controls
59 lines (50 loc) · 1.56 KB
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
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
const fs = require('fs');
var long_string = fs.readFileSync(__dirname + "/tweetfromhere.txt").toString();
//var stat = {status: stringy};
// {status: 'I like pizza'}
// client.post('statuses/update', stat, function(error, tweet, response) {
// if(error)
// {
// console.log(error);
// }
// //console.log(tweet); // Tweet body.
// //console.log(response); // Raw response object.
// });
var short_string = new String("");
const tweet_length = 140;
if (long_string.length%tweet_length === 0)
{
var num_tweets = long_string.length/tweet_length;
}
else
{
var num_tweets = Math.floor(long_string.length/tweet_length);
console.log(num_tweets)
}
var stats = [];
for (i = 0; i <= num_tweets; i++)
{
short_string = long_string.substr(i*tweet_length, tweet_length);
stats.push({status: short_string});
}
stats.forEach(function(element, index, array){
(function(e){ //Closure function
setTimeout(function(){
client.post('statuses/update', e, function(error, tweet,response) {
if(error)
{
console.log(error);
}
//console.log(tweet); // Tweet body.
console.log(response); // Raw response object.
});
}, 3000);
})(element);
});