Advertisement
Guest User

steem.js post details by votes

a guest
May 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const steem = require('steem');
  2. const username = 'YOUR_USERNAME';
  3.  
  4. function getAccountVotes(author) {
  5.   return new Promise((resolve, reject) => {
  6.     steem.api.getAccountVotes(author, (error, result) => {
  7.       if (error) {
  8.         reject(error);
  9.       } else {
  10.         resolve(result);
  11.       }
  12.     });
  13.   });
  14. }
  15.  
  16. function getContent(author, permlink) {
  17.   return new Promise((resolve, reject) => {
  18.     steem.api.getContent(author, permlink, (error, result) => {
  19.       if (error) {
  20.         reject(error);
  21.       } else {
  22.         resolve(result);
  23.       }
  24.     });
  25.   });
  26. }
  27.  
  28. getAccountVotes(username)
  29.   .then(async (votes) => {
  30.     const lastTenVotes = votes.reverse().slice(0, 10);
  31.     const posts = await Promise.all(lastTenVotes.map((vote) => {
  32.       const authorPerm = vote.authorperm.split('/');
  33.       return getContent(authorPerm[0], authorPerm[1]);
  34.     }));
  35.  
  36.     console.log(posts.map(p => p.title));
  37.   })
  38.   .catch(err => console.log(err));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement