-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfollow_trending_authors.js
91 lines (65 loc) · 2.3 KB
/
follow_trending_authors.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
var steem = require('steem');
var config = require('./config');
steem.api.setOptions({ url: config.steem.url });
var wif = steem.auth.toWif(config.steem.username, config.steem.password, config.steem.auth_type);
var followingArray = [];
function uniq(a) {
return a.sort().filter(function(item, pos, ary) {
return !pos || item != ary[pos - 1];
})
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function startFollowAccountsInTrending(result) {
var trending_tags = result.tag_idx.trending;
for(var attributename in trending_tags) {
console.log(attributename+": "+trending_tags[attributename]);
steem.api.getState('/trending/'+trending_tags[attributename], function(err, result) {
followAccountsInTrending(result);
});
await sleep(config.steem.delay);
}
}
async function followAccountsInTrending(result) {
var content = result.content;
var accounts = result.accounts;
for(var attributename in accounts) {
//console.log(attributename+": "+accounts[attributename]);
var following = accounts[attributename].name;
if( followingArray.indexOf(following) !== -1 ) {
console.log("This item already exists");
continue;
}
let followReq = ["follow"]
followReq.push({follower: config.steem.username, following: following, what: ["blog"]})
const customJson = JSON.stringify(followReq)
console.log( followReq );
followingArray.push(following);
steem.broadcast.customJsonAsync(wif, [], [config.steem.username], "follow", customJson)
.then(console.log)
.catch(console.log)
await sleep(config.steem.delay);
console.log( followingArray );
}
}
//TODO move this to library.js
function getFollowing(start=config.steem.user,count=100) {
//console.log( 'test' );
steem.api.getFollowing(config.steem.username, start, 'blog', 100, function(err, result){
start = '';
count = result.length;
//Inner loop: the followings' accounts following.
for (let i = 0; i < count; i++) {
followingArray.push(result[i].following);
start = result[i].following;
}
if( count === 100 )
getFollowing( start, count );
else
steem.api.getState('/trending', function(err, result) {
startFollowAccountsInTrending(result);
});
});
}
getFollowing();