-
Notifications
You must be signed in to change notification settings - Fork 2
/
tweet.js
65 lines (55 loc) · 1.91 KB
/
tweet.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
var Twit = require('twit')
fs = require('fs'),
path = require('path'),
Twit = require('twit'),
shuffle = require('shuffle-array'),
config = require(path.join(__dirname, 'config.js'));
function tweetImage() {
var tweet = new Twit(config);
// Define images path
var imagesArray = fs.readdirSync('./images/');
// Shuffle images
shuffle(imagesArray);
// Pick random image
var randImage = shuffle.pick(imagesArray);
console.log("IMAGE CHOSEN: " + randImage);
// Convert content to base64
var b64content = fs.readFileSync('./images/' + randImage, {
encoding: 'base64'
});
// Assign b64 content to tweet
tweet.post('media/upload', {
media_data: b64content
},
function(err, data, response) {
if (err) {
console.log('ERROR');
console.log(err);
}
else {
console.log('UPLOADING....');
// Post tweet
tweet.post('statuses/update', {
media_ids: new Array(data.media_id_string)
},
function(err, data, response) {
if (err) {
console.log('ERROR');
console.log(err);
}
else {
console.log('_______________________________________________________');
console.log(' BLANKBOT HAS TWEETED AN IMAGE!');
console.log(' http://twitter.com/blank_waves');
console.log('_______________________________________________________');
// Delete image after tweeting
fs.unlinkSync('./images/' + randImage);
}
}
);
}
});
}
setInterval(function() {
tweetImage();
}, 30 * 60 * 1000); // Tweets in 30 minute intervals