Repository navigation
Expand file tree
/
Copy pathbot.js
More file actions
74 lines (57 loc) · 1.8 KB
/
Copy pathbot.js
File metadata and controls
74 lines (57 loc) · 1.8 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
console.log('Bot Starting');
const fs = require('fs');
var Twit = require('twit');
var config = require('./config');
var image_list = [];
for (var i = 1; i <= 17; i++) {
image_list.push(i);
}
var images_posted = 0;
var T = new Twit(config);
console.log('Connected to Twitter');
function fcn_tweeted(err, data, response) {
if (err) {
console.log("Issue posting tweet");
}
else {
console.log("Posted");
}
console.log(data);
}
function post_tweet(img_path) {
var b64content = fs.readFileSync(img_path, { encoding: 'base64' });
T.post('media/upload', { media_data: b64content }, function (err, data, response) {
var mediaIdStr = data.media_id_string;
var altText = "It's Amazing!";
var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } };
T.post('media/metadata/create', meta_params, function (err, data, response) {
if (!err) {
// now we can reference the media and post a tweet (media will attach to the tweet)
var params = { status: "It's Amazing!", media_ids: [mediaIdStr] };
T.post('statuses/update', params, function (err, data, response) {
console.log("I just posted the file at " + img_path);
})
}
})
})
}
function shuffle_images(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function fact_time() {
var image_loc = "images/IMG" + image_list[images_posted] + ".jpg";
if (images_posted < 16) {
images_posted ++;
}
else {
shuffle_images(image_list);
images_posted = 0;
}
post_tweet(image_loc);
var time_period = 1000*60*60*(Math.random()*6 + 10);
setTimeout(fact_time, time_period)
}
fact_time();