djimirji

Untitled

May 29th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ======================= Коннект ==========================
  2. //const GOLOSNODE = "ws://localhost:9090"
  3. //const GOLOSNODE = "wss://api.golos.cf"; //нода @vik
  4. const GOLOSNODE = "wss://ws.golos.io"; //ropox
  5. // Подключение JavaScript библиотеки для работы c API голоса
  6. const golos = require('golos-js');
  7. // Указываем ноду, к которой будет подключен скрипт
  8. golos.config.set('websocket', GOLOSNODE);
  9. // =====================================================================
  10.  
  11. //#######################################################################
  12. function findActiveVotes (author , permlink) {
  13.     return golos.api.getActiveVotes(author, permlink, function(err, result) {
  14.         if(err){console.log(err);}     
  15.     });
  16. }
  17. //#######################################################################
  18. function checkAccount (voter) {
  19. //  let names = [voter];
  20.     return golos.api.getAccounts(voter, function(err, result) {
  21.         if(err){console.log(err);}     
  22.     });
  23. }
  24. //#######################################################################
  25. function ReceiveBlog (author,permlink) {
  26.     return golos.api.getContent(author, permlink, function(err, result) {
  27.         if(err){console.log(err);}             
  28.     });
  29. }
  30.  
  31. //#######################################################################
  32.  
  33. function findblogs (coments) {  
  34.     return new Promise(function(resolve, reject) {     
  35.         let blogdata = [];
  36.         for (z=0;z < coments.length;z++ ){         
  37.             blogdata.push(ReceiveBlog(coments[z].blogauthor,coments[z].bloglink))                          
  38.             if (z == coments.length - 1) {
  39.                 resolve(Promise.all(blogdata))
  40.             }
  41.         }  
  42.     })
  43. }
  44.  
  45. function findWeeklyPosts (blogs) {     
  46.     return new Promise(function(resolve, reject) {
  47.         let blogdata = [];
  48.         for (z=0;z < blogs.length;z++ ){
  49.             let blogcreated = new Date(new Date(blogs[z].created).getTime() + (3*1000*60*60));
  50.             if ((blogcreated > lastMonday) && (blogcreated < lastSunday)) {
  51.                 let blogurl = blogdata.map(a => a.url);
  52.                     if (blogurl.includes(blogs[z].url)) {
  53.                         continue;
  54.                     }
  55.                     else {
  56.                         fill = {
  57.                             author: blogs[z].author,
  58.                             permlink: blogs[z].permlink,                           
  59.                             children: blogs[z].children,
  60.                             bloglength: blogs[z].body.length,
  61.                             author_reputation: blogs[z].author_reputation,
  62.                             url: blogs[z].url,                     
  63.                             title: blogs[z].title
  64.                         }
  65.                         blogdata.push(fill);
  66.                     }              
  67.             }
  68.             if (z == blogs.length - 1) {
  69.                 resolve(Promise.all(blogdata))
  70.             }
  71.         }      
  72.     })
  73. }
  74.  
  75. function findVotes (blogs) {
  76.     return new Promise(function(resolve, reject) {
  77.         let blogdata = [];
  78.         for (z=0;z < blogs.length;z++ ){
  79.             let activevotes = findActiveVotes (blogs[z].author, blogs[z].permlink)
  80.                 fill = {
  81.                     post: blogs[z],
  82.                     activevotes: activevotes
  83.                 }
  84.                 blogdata.push(fill)        
  85.             if (z == blogs.length - 1) {
  86.                 resolve(blogdata);
  87.                
  88.             }
  89.         }  
  90.     })
  91. }
  92.  
  93. async function getavrhash(activevotes) {
  94.         let not_bot = [];
  95.         let voters = activevotes.map(a => a.voter)
  96.         let vt = await checkAccount(voters);   
  97.         for (let v of vt) {
  98.             if ((v.proxy == '') && (v.recovery_account == 'golosio') && !(blacklistvoters.includes(v.name)) && (parseInt(v.reputation) > 9999999999) ) {
  99.                 not_bot += v.name;
  100.             };     
  101.         }
  102.         return (not_bot);  
  103. };
  104.  
  105. //let not_bot_array = activevotes.filter(function(obj) { return notbot.indexOf(obj.voter) == -1; })
  106. const collectposts = new Promise(function(resolve, reject) {
  107.     getlastweekcomments    
  108.         .then (function (result,err){
  109.             console.log("Всего коментариев:",result.length)        
  110.             findblogs (result)             
  111.                 .then (function (result,err){                                  
  112.                     console.log("Всего постов с начала даты:",result.length)         
  113.                     findWeeklyPosts (result)
  114.                         .then (function (result,err){
  115.                             console.log("Всего подходящих постов:", result.length);
  116.                             findVotes (result)
  117.                                 .then (function (result,err){                                  
  118.                                     resolve(result)
  119.                                 })
  120.                                 .catch(err => {
  121.                                     console.log("PROMISE Не удалось вычеслить findVotes")
  122.                                     resolve(undefined)
  123.                                 })
  124.                            
  125.                         })
  126.                         .catch(err => {
  127.                             console.log("PROMISE Не удалось вычеслить findWeeklyPosts")
  128.                             resolve(undefined)
  129.                         })
  130.                    
  131.                    
  132.                 })
  133.                 .catch(err => {
  134.                     console.log("PROMISE Не удалось вычеслить findblogs")
  135.                     resolve(undefined)
  136.                 })         
  137.         })
  138.         .catch(err => {
  139.             console.log("PROMISE Не удалось вычеслить getlastweekcomments")
  140.             resolve(undefined)
  141.         })
  142. })
  143.  
  144. //############################################
  145.  
  146. async function runBot() {
  147.     let data = await collectposts
  148.     //let activevotes = await findRealVotes (data)
  149.     console.log(data [9])
  150. }
  151.  
  152. runBot()
Advertisement
Add Comment
Please, Sign In to add comment