Automation of analysis of active community members. Version 1.3 + telegram bot

in Steem-BRU (BY-RU-UA)3 years ago

image.png

Теперь не нужно 50 раз запускать скрипт. Он самостоятельно обрабатывает весь список

const fs = require("fs");
const steem = require('steem');
let xc, input, hive, fullbody;
var body2R;
var body3R;
var author;
var permlinkR;

let wifkey = 'asdasdasdasdasdasdasdasdasdasd';
let votey = "alexmove";
body3R = '';

function words(body) 
{
                
    //let words = body1.split(" ");
        var wordsCount = body.reduce(function (acc, w) {
        if(acc[w]) {
            acc[w] += 1
        } else {
            acc[w] = 1;
        }
        
        return acc;
        }, {});
     
        for (var w in wordsCount) 
        {
            console.log('Cлово "%s" встречается %d раз', w, wordsCount[w]);

            if (wordsCount[w]>2) {
            if (w.length>4)  {

              body3R = body3R +  `| @`+author + ` | ` + `<a href="https://steemit.com/@${author}/${permlinkR}">` + permlinkR + ` </a> |`+ w +` | ` + wordsCount[w]+ ' | \n';

            }
            }
        }
        
              fs.appendFileSync("bdLOG.txt",body3R);

}


      var err;
    
        let accounts = fs.readFileSync('spisok.txt').toString().split(" ");
        console.log(accounts);


        accounts.forEach(function (element,i,array){
                         steem.api.getDiscussionsByComments({
                                    "start_author": element,
                                    "limit": 100
                                }, function (err, result) {

                                    
                if (err === null) {
                     var stat = 0;
                      console.log(stat);

                    var i, len = result.length;
                    for (i = 0; i < len; i++) {
                        
                        var discussion = result[i];
                        var d = new Date(); // Today!
                        d.setDate(d.getDate() - 1); // Yesterday!
                        d = d.toJSON().split("T")[0];
                        
                        permlinkR = discussion.permlink;
                        
                        author = discussion.author;
                        input = discussion.created;
                        hive = discussion.category;

                        console.log(input);
                        if ((input.indexOf(d) !== -1) && (hive === 'hive-171319')) {
                          stat = stat+1;
                          fullbody = fullbody + ' ' + discussion.body;

                    }}
                            
                console.log(fullbody);
                body = fullbody.split(" ");
                words(body);
                            
                    }
                    
                        qu2 = element+' '+stat+"\r\n";
                        fs.appendFile("brustat.txt", qu2, (err) => { 
                          if (err) { 
                            console.log(err); 
                          } 
                        }); 
                    }
                    
                    );

}
);

        


Прошлые версии:

https://steemit.com/hive-171319/@alexmove/with-word-frequency-detection-automation-of-analysis-of-active-community-members
https://steemit.com/hive-171319/@alexmove/test-working-scripts-automation-of-analysis-of-active-community-members

telegram.bot
@brustat_bot

const TelegramBot = require('node-telegram-bot-api');
const steem = require('steem');
const fs = require("fs");


    

// replace the value below with the Telegram token you receive from @BotFather
const token = 'sdfsdfsdfsdf';

// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});

// Matches "/echo [whatever]"
bot.onText(/\/echo (.+)/, (msg, match) => {
  // 'msg' is the received Message from Telegram
  // 'match' is the result of executing the regexp above on the text content
  // of the messag


});


// Listen for any kind of message. There are different kinds of
// messages.
bot.on('message', (msg) => {
  const chatId = msg.chat.id;
const { id } = msg.chat;

//bot.sendMessage(chatId, msg.text);
  // send a message to the chat acknowledging receipt of their message

if (msg.text === "stat")
{
    let array = fs.readFileSync('brustat_bot.txt');
    //let test_a = array[0].split(' ');
        console.log(array);
    bot.sendMessage(chatId, array);
    
}
else if (msg.text === "puaro_del")
{

}                       
else if (msg.text === "puaro_array")
{


    let data = fs.readFileSync('brustat_bot.txt').toString();
    let ar2= [];
    let summ_test = 0;

        var first=data.split('\n');
                //console.log(second[i]," ");

        var second = new Array();
        for(i=1;i<first.length;i++)
        {
            second[i] = first[i].substring(first[i].indexOf(" ")+1);    
            summ_test =  Number(summ_test)+ Number(second[i]);
        
        console.log(first[i]);
        console.log(second[i]);
        console.log(summ_test); // 16

  ar2.push([ first[i], second[i] ]);
        }

ar2.sort(function (a, b) {
    return a.price - b.price;
});

ar2.sort(function(a, b) {
  return (a[0] - b[0]) || (a[1] - b[1]);
});
ar2.reverse;
console.log(ar2);

    fs.writeFile("brustat_sort.txt", ar2.join('|'), (err) => { 
      if (err) { 
        console.log(err); 
      } 
    });
    
}
else if (msg.text === "puaro")
{
    
    
const fs = require("fs");
const steem = require('steem');
let xc, input, hive, fullbody;
var body2R;
var body3R;
var author;
var permlinkR;

                    fs.writeFile("brustat.txt", "", (err) => { 
                          if (err) { 
                            console.log(err); 
                          } 
                        });
                        
let wifkey = 'sdfsdfsdfsdf';
let votey = "alexmove";
body3R = '';

function words(body) 
{
                
    //let words = body1.split(" ");
        var wordsCount = body.reduce(function (acc, w) {
        if(acc[w]) {
            acc[w] += 1
        } else {
            acc[w] = 1;
        }
        
        return acc;
        }, {});
     
        for (var w in wordsCount) 
        {
            console.log('Cлово "%s" встречается %d раз', w, wordsCount[w]);

            if (wordsCount[w]>2) {
            if (w.length>4)  {

              body3R = body3R +  `| @`+author + ` | ` + `<a href="https://steemit.com/@${author}/${permlinkR}">` + permlinkR + ` </a> |`+ w +` | ` + wordsCount[w]+ ' | \n';

            }
            }
        }
        
              fs.appendFileSync("bdLOG.txt",body3R);

}


      var err;
    
        let accounts = fs.readFileSync('spisok.txt').toString().split(" ");
        console.log(accounts);


        accounts.forEach(function (element,i,array){
                         steem.api.getDiscussionsByComments({
                                    "start_author": element,
                                    "limit": 100
                                }, function (err, result) {

                                    
                if (err === null) {
                     var stat = 0;
                      console.log(stat);

                    var i, len = result.length;
                    for (i = 0; i < len; i++) {
                        
                        var discussion = result[i];
                        var d = new Date(); // Today!
                        d.setDate(d.getDate()); // Yesterday!
                        d = d.toJSON().split("T")[0];
                        
                        permlinkR = discussion.permlink;
                        
                        author = discussion.author;
                        input = discussion.created;
                        hive = discussion.category;

                        console.log(input);
                        if ((input.indexOf(d) !== -1) && (hive === 'hive-171319')) {
                          stat = stat+1;
                          fullbody = fullbody + ' ' + discussion.body;

                    }}
                            
                console.log(fullbody);
                body = fullbody.split(" ");
                words(body);
                            
                    }
                    
                        qu2 = element+' '+stat+"\r\n";
                        fs.appendFile("brustat_bot.txt", qu2, (err) => { 
                          if (err) { 
                            console.log(err); 
                          } 
                        }); 
                    }
                    
                    );

}
);
    

}
else if (msg.text === "help")
{
    bot.sendMessage(chatId, `Если хотите получить статистику - напишите stat. Администратор может обновить статистику. 
    
    Чтобы обновить статистику:
    
    Командо puaro 

     Подробности: https://steemit.com/hive-171319/@alexmove/sozdanie-interaktivnogo-reitinga-soobshestva-steem-bru-podschet-kommentariev-na-nodejs-dlya-steemit`);
                        

}
else
{
    
                        var err;
        console.log(chatId);
                    //  bot.sendMessage(chatId, chatId);
                    //  bot.sendMessage(chatId, msg.text);
                        bot.sendMessage(chatId, ' Чтобы просмотреть статистику. Отправьте боту слово stat. Спасибо');
    
    test_c(msg.text);
                


}
        
});

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.029
BTC 66426.55
ETH 3459.91
USDT 1.00
SBD 2.62