-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom-reblog.js
133 lines (111 loc) · 5.19 KB
/
random-reblog.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//______________________________STOCHASTIQUE_BLOG_Bot___________________________
//----------------_________________RANDOM_REBLOG_____________-------------------
//______________________MADE___BY___NIEMES_____INFO =-} niemes.info_____________
// -----------------------------------------------------------------------------
var jsonfile = require('jsonfile'),
tagFile = './tags.json',
oldPostFile = './old_ids.json';
var tumblr = require('tumblr.js');
var client = tumblr.createClient({
consumer_key: 'your_consumer_key',
consumer_secret: 'your_consumer_secret',
token: 'your_token',
token_secret: 'your_token_secret'
});
var tagObj = {
'tags': []
};
var old = {
'ids': []
};
function readList() {
jsonfile.readFile(tagFile, function(err, obj) {
tagObj.tags = obj.tags;
function init() {
var postNumber = 244; // Number of Post every 24H. (250 max)
var timeToPost = 86400000 / postNumber;
console.log("-------- INIT --------");
var reblogKey = [],
postList = [],
postIdList = [];
// starter tag.
function GetPostKey() {
var randTag = Math.floor((Math.random() * tagObj.tags.length) + 1);
var tag = tagObj.tags[randTag];
client.taggedPosts(tag, {
filter: 'html'
}, function(err, data) {
if (data !== null && data.length !== null) {
for (var i = 0; i < data.length; i++) {
if (data[i].tags !== undefined && (data[i].reblog_key !== undefined || data[i].id !== undefined)) {
reblogKey.push(data[i].reblog_key);
postIdList.push(data[i].id);
if (tagObj.tags.length < 35000) { // ex 5000 - Size limit of the taglist
if (data[i].tags.length !== 0) {
for (var j = 0; j < data[i].tags.length; j++) {
if (tagObj.tags.indexOf(data[i].tags[j]) == -1) {
tagObj.tags.push(data[i].tags[j]);
}
} //grab some tags.
}
}
}
}
if (err) {
console.log('TAG Problem ' + err);
} else {
console.log('Tags/Keys/Ids catched -= OK =- ');
jsonfile.writeFile(tagFile, tagObj, {
spaces: 2
}, function(err) {
if (err !== null) {
console.log("error jsonfile writeFile error : ", err);
}
});
}
}
});
}
GetPostKey();
setInterval(GetPostKey, 15000); // Time to grab post = id + key
function reblogMachine() {
jsonfile.readFile(oldPostFile, function(err, obj) {
old.ids = obj.ids;
var randKey = Math.floor((Math.random() * reblogKey.length) + 1);
var key = reblogKey[randKey];
var postId = postIdList[randKey];
var blogName = 'your_blog.tumblr.com';
var myCom = 'your_comment.'; // comment: if you want to add a comment on every rebloged-post. Leave empty if you want.
if (key !== undefined && postIdList.length !== 0) {
if (old.ids.indexOf(postId) == -1) {
client.reblogPost(blogName, {
id: postId,
reblog_key: key,
comment: myCom
}, function(err, data) {
if (err) {
console.log('Reblog Problem' + err);
} else {
old.ids.push(postId);
jsonfile.writeFile(oldPostFile, old, {
spaces: 2
}, function(err) {
if (err !== null) {
console.log("jsonfile error old_ids.json writeFile : ", err);
}
});
// --------- ERROR LOG -----------
console.log('Reblog -= [OK] =- ');
}
});
}
}
});
}
setInterval(reblogMachine, timeToPost);
console.log("Time/min before every post : " + parseInt(((timeToPost / 1000) / 60)) + "mins");
}
init();
});
}
readList();