Skip to content

Instantly share code, notes, and snippets.

@jonmaim
Created December 16, 2018 15:48
Show Gist options
  • Save jonmaim/bdd8ba60c16a4397921503eacc410ed2 to your computer and use it in GitHub Desktop.
Save jonmaim/bdd8ba60c16a4397921503eacc410ed2 to your computer and use it in GitHub Desktop.
Get the commenters list from your last Steem post
'use strict';
/* to be filled up */
const selfName = 'jonmaim';
const postingWif = 'xxx';
const steem = require('steem');
const timeout = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function forEach(array, callback) {
return new Promise(async resolve => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
return resolve();
});
}
function getComments(name, permlink) {
return new Promise(async resolve => {
steem.api.getContentReplies(name, permlink, async (err, parentComments) => {
if (err) { throw err; }
let comments = [];
await forEach(parentComments, async function(c) {
console.log('-', c.author);
if (c.children > 0) {
const childrenComments = await getComments(c.author, c.permlink);
childrenComments.forEach(cc => comments.push(cc));
}
});
comments = parentComments.concat(comments);
return resolve(comments);
});
});
}
async function getLastPost(u) {
return new Promise(resolve => {
steem.api.getDiscussionsByBlog({tag: u, limit: 1}, async (err, posts) => {
if (err) { throw err; }
if (!posts.length) { return resolve(); }
const p = posts[0];
const comments = await getComments(p.author, p.permlink);
console.log('done', p.author, p.permlink);
let authors = {};
comments.forEach(c => {
authors[c.author] = true;
console.log(c.author);
});
console.log('# comments', comments.length);
console.log('@' + Object.keys(authors).reduce((acc, v) => v + ' | @' + acc));
return resolve();
});
});
}
(async function() {
await getLastPost(selfName);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment