Actual scripts of User Activity Rank (Nodejs)

in SteemAlive2 years ago

Scripts of User Activity Rank.png

Steem posts are stored on the blockchain and are very secure. Therefore, in order not to lose the development that is important for me, I will publish the scripts in the post.

The version without the latest changes can be found on github, it is working there, since I made the last changes to work with the site SteemLive and other users do not need these changes.

NodeJs Scripts:
https://github.com/Alexmovelove/User-Activity-Rank.git

Order to run Rank:

(if for community) spisok_twg
create
addcom
addpost
create_day
sortcom
sortcom
sortpost
sortpost
sum
listcom
(if you want publick comrank) postcom
listpost
(if you want publick postrank) postpost
fulllist
fulllistpost

Scripts in alphabetical order:

Script addcom.js


const fs = require("fs");
const steem = require('steem');
let input, hive, fullbody, x1;
var author,author2;
var permlinkR;
var err;
let stat, stat2; 

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}





    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;


             
//let array = fs.readFileSync('spisok.txt').toString().split("\n");
//let test_a = array[0].split(' ');


      const mysql = require("mysql2");

  const sql = `SELECT * FROM spisok`;
    //const sql = `SELECT * FROM p0111 ORDER BY length DESC`;
    //     console.log(sql);   

const connection = mysql.createConnection(config);


  connection.query(sql,  function(err, results) {
        if(err) console.log(err);
             console.log(results);   
        let test_a = results;
                   //  console.log(results[2]['author']);   


len1 = test_a.length-1;
 console.log(len1); 
for (x1 = 0; x1 < len1; x1++) {

    steem.api.getDiscussionsByComments({
                    "start_author": test_a[x1]['author'],
                   // "start_author": 'allfabeta',
                    "limit": 100
                }, function (err, result) {
                    console.log(err, result);
                    if (err === null) {
                    stat = 0;
                    console.log(x1);
                     console.log(test_a[x1]['author']);

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

                        if (input.indexOf(d) !== -1) {
                          stat=stat+1;
                          stat2 = stat;
                          fullbody = fullbody + ' ' + discussion.body;
                        }}
                            
                            const mysql = require("mysql2");
  
const connection = mysql.createConnection(config);

connection.on('error', function() {});

let sql22 = `create table if not exists ${mytable_c}(
  id int primary key auto_increment,
  author varchar(255) not null,
  count int not null,
  points float not null
  )`;
  
        connection.query(sql22, function(err, results) {
                    if(err) console.log(err);
                    console.log(results);
                    });    
                    
                    
                    const sql = `INSERT INTO ${mytable_c}(author, count,points) VALUES('${author}', '${stat}','0')`;

                    connection.query(sql, function(err, results) {
                    if(err) console.log(err);
                    console.log(results);
                    });     

connection.end();

                    console.log('68 строка');           

                    console.log(stat,author);           
                                        
                    } else {
                        console.log('внимание поломка поломка поломка поломка');
                }}
                    
            
                    );


}


  });

Script addpost.js

const fs = require("fs");
const steem = require('steem');
//let accounts = fs.readFileSync('spisok.txt').toString().split(" ");
//console.log(accounts);
accounts = 0;
var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}


    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;


//accounts.forEach(function (element,i,array){
    
      const mysql = require("mysql2");

const connection = mysql.createConnection(config);


  
  const sql = `SELECT * FROM spisok`;
    //const sql = `SELECT * FROM p0111 ORDER BY length DESC`;
    //     console.log(sql);   

  connection.query(sql,  function(err, results) {
        if(err) console.log(err);
             console.log(results[2]['author']);   

        users = results;
        accounts = users;
console.log(accounts);


len = accounts.length;
 for (yyy = 0; yyy < len; yyy++) 

{
      console.log('yyy');
      console.log(yyy);
      
    
    steem.api.getDiscussionsByAuthorBeforeDate(accounts[yyy]['author'],null, new Date().toISOString().split('.')[0],20 , function(err, result) {
     if (result)
     {      // console.log(result);
       
       
        var i, len = result.length;
                    for (i = 0; i < len; i++) 
                    {
                                                    
                       var raw = result[i];
                       console.log('Автор');
                       console.log(raw.author);
                       console.log('Заголовок');
                       console.log(raw.author);
                     console.log('Сообщество');

                       console.log(raw.category);
                         console.log('Длина поста');
                       console.log(raw.body_length);
                         console.log('Количество ожидаемого вознаграждения');
                       console.log(raw.pending_payout_value);
     console.log('Количество комментариев');                     
                     console.log(raw.replies.length);
                         console.log('Количество upvote');
                        let upvote = raw.active_votes.length-1;
                       console.log(raw.active_votes.length-1);
     console.log('Дата создания');                   
                       console.log(raw.created);
    let input = raw.created;
    var d = new Date(); // Today!

                        d.setDate(d.getDate() - num_day); // Yesterday!
                        d = d.toJSON().split("T")[0];
            let title = raw.title;

    title = title.replace(/[^a-zа-яё0-9\s]/gi, ' ');
            
    if (input.indexOf(d) !== -1)

    {
    body3R =  `| `+raw.author + `| <a href="`+raw.url+`">` + title + `</a>| `+ upvote + `| ` +  `????`  + `| ` + raw.children+`| ` + raw.body_length+ ' | \n';
    console.log(body3R);
    
            const mysql = require("mysql2");
  
const connection = mysql.createConnection(config);

connection.on('error', function() {});


let sql44 =  `create table if not exists ${mytable_p}( id int primary key auto_increment, author varchar(255) not null, title varchar(255) not null, created varchar(255) not null, length int not null, url varchar(255) UNIQUE KEY, comments int not null, upvotes int not null, points float not null, percent float not null)`;
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);

         connection.query(sql44, function(err, results) {
                    if(err) console.log(err);
                    console.log(results);
                    });     

                    const sql = `INSERT INTO ${mytable_p}(author, title, created, length, url, comments, upvotes, points,percent) VALUES('${raw.author}','${title}', '${raw.created}', '${raw.body_length}', '${raw.url}', '${raw.children}', '${upvote}','0','999')`;

                    connection.query(sql, function(err, results) {
                    if(err) console.log(err);
                    console.log(results);
                    });     

connection.end();

        console.log(raw.created);
            fs.appendFileSync("rank.txt",body3R);

    }
}
     }


    });

}

});


connection.end();

Script config.js

exports.num_day = 1;
exports.wifkey = "xxx";
exports.account = "xx";

    var d = new Date(); // Today!
    d.setDate(d.getDate()-exports.num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    
exports.bd_name = "club";
exports.user_mysql = "xxx";
exports.password_mysql = "xxx";
exports.hive_name = "hive-153018";
exports.image_list = `xxx`;
exports.title_name = "rank";
exports.url_post = `
!xxx`;



Script create.js

//(поменять название таблицы)
//Создать пост в стимите.

/*
node /mnt/disk15/familyrank/User-Activity-Rank/create.js
node /mnt/disk15/familyrank/User-Activity-Rank/create_spisok.js
node /mnt/disk15/familyrank/User-Activity-Rank/spisok.js
node /mnt/disk15/familyrank/User-Activity-Rank/addcom.js
node /mnt/disk15/familyrank/User-Activity-Rank/addpost.js
node /mnt/disk15/familyrank/User-Activity-Rank/create_day.js
node /mnt/disk15/familyrank/User-Activity-Rank/sortcom.js
node /mnt/disk15/familyrank/User-Activity-Rank/sortcom.js
node /mnt/disk15/familyrank/User-Activity-Rank/sortpost.js
node /mnt/disk15/familyrank/User-Activity-Rank/sortpost.js
node /mnt/disk15/familyrank/User-Activity-Rank/sum.js
node /mnt/disk15/familyrank/User-Activity-Rank/listcom.js
node /mnt/disk15/familyrank/User-Activity-Rank/listpost.js
node /mnt/disk15/familyrank/User-Activity-Rank/fulllist.js
node /mnt/disk15/familyrank/User-Activity-Rank/fulllistpost.js
*/

/*
spisok_twg
create
addcom
addpost
create_day
sortcom
sortcom
sortpost
sortpost
sum
listcom
postcom
listpost
postpost
fulllist
fulllistpost
*/

let date_know;

const mysql = require("mysql2");
 var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}

const connection = mysql.createConnection(config);




    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;

let sql8 = `create database ${bd_name}`;
console.log(sql8);                       

connection.query(sql8, function(err, results) {
if(err) console.log(err);
else console.log("Таблица создана");
});

/*
let sql = `create table if not exists ${mytable_p}(
  id int primary key auto_increment,
  author varchar(255) not null,
  title varchar(255) not null,
  length int not null,
 url varchar(255) UNIQUE KEY,
 comments int not null,
upvotes int not null,
 points float not null)`;

*/

let sql2 = `create table if not exists ${mytable_c}(
  id int primary key auto_increment,
  author varchar(255) UNIQUE KEY,
  count int not null,
  points float not null
  )`;
  
let sql3 = `create table if not exists ${mytable}(
  id int primary key auto_increment,
  author varchar(255) UNIQUE KEY,
  comments float not null,
  posts float not null,
  points float not null 
  )`;
 console.log(sql3);
 
let sql44 =  `create table if not exists ${mytable_p}( id int primary key auto_increment, author varchar(255) not null, title varchar(255) not null, created varchar(255) not null, length int not null, url varchar(255) UNIQUE KEY, comments int not null, upvotes int not null, points float not null, percent float not null)`;
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);
                    console.log(sql44);

         connection.query(sql44, function(err, results) {
                    if(err) console.log(err);
                    console.log(results);
                    });     

 connection.query(sql2, function(err, results) {
    if(err) console.log(err);
    else console.log("Таблица создана");
});

 connection.query(sql3, function(err, results) {
    if(err) console.log(err);
    else console.log("Таблица создана");
});

connection.end();

Script create_day.js

const mysql = require("mysql2");
  
var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}

const connection = mysql.createConnection(config);



    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;


let sql_day = `create table if not exists ${mytable}(
  id int primary key auto_increment,
  author varchar(255) UNIQUE KEY,
  comments float not null,
  posts float not null,
  points float not null 
  )`;
 console.log(sql_day);
 
 connection.query(sql_day,function(err, results) {
    if(err) console.log(err);   });


const sql = `SELECT * FROM spisok`   ;

    console.log(sql);

connection.query(sql,  function(err, results) {
    if(err) console.log(err);
    
    const users = results;
    console.log(users);
    console.log(users.length);
    console.log(users.length);
    console.log(users.length);
    console.log(users.length);
    console.log(users.length);
    for(let i=0; i < users.length; i++){


        let author = users[i].author;
        const sql4 = `INSERT INTO ${mytable}(author, comments, posts, points) VALUES('${author}', '0','0','0')`;
        
            console.log(sql4);

            connection.query(sql4,function(err, results) {
                if(err) console.log(err);   });
    }
});



Script create_spisok.js

//CREATE DATABASE [IF NOT EXISTS] имя_базы_даных;


const mysql = require("mysql2");

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}

const connection = mysql.createConnection(config);

let mytable_p = 'posts01';
let mytable_c = 'c1711';
let mytable_day = 'a1711';

let sql = `create table if not exists spisok( id int primary key auto_increment, author varchar(255) UNIQUE KEY)`;

//let sql = `create table if not exists post_number( id int primary key auto_increment, number int)`;

connection.query(sql, function(err, results) {
if(err) console.log(err);
else console.log("Таблица создана");
});

connection.end();



Script createreport.js

//CREATE DATABASE [IF NOT EXISTS] имя_базы_даных;


const mysql = require("mysql2");

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}

const connection = mysql.createConnection(config);

let mytable_p = 'posts01';
let mytable_c = 'c1711';
let mytable_day = 'a1711';

let sql = `create table if not exists spisok( id int primary key auto_increment, author varchar(255) UNIQUE KEY)`;

//let sql = `create table if not exists post_number( id int primary key auto_increment, number int)`;

connection.query(sql, function(err, results) {
if(err) console.log(err);
else console.log("Таблица создана");
});

connection.end();



Script fulllist.js



const mysql = require("mysql2");
  

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}

const connection = mysql.createConnection(config);


let formula;

    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    
let mytable = 'a'+d;
let name_file = bd_name+d+".txt";
let name_file_report = "/var/www/steemlive/report/"+bd_name+d+".txt";

console.log(mytable);

let full = `
![image.png](https://cdn.steemitimages.com/DQmegdp1ukWAqQiX2gdFNeMNcWQn5WDufxpTE2zRuUYvcxz/image.png)


Today's lider of Rank: @xxxxx

Thank you for your activity! The leader of the rating receives a reward in the form of upvotes of the entire rating support team. The description of the command is below. I invite you to join the team. Every cent and every upvote counts!


<a href="https://steemit.com/steemit/@alexmove/it-is-important-please-vote-steem-market-rating-and-uniqueness-check
">Please see more information about our project here</a>

<h2>Rating for the day</h2>
|N|account|points for comments|points for posts|total score for the day|
------------|-------------|------------|-------------|---------|`;




const sql = `SELECT * FROM ${mytable} ORDER BY points DESC` ;

    console.log(sql);

connection.query(sql,  function(err, results) {
    if(err) console.log(err);
    const users = results;
    console.log('users');
    console.log('users');
    console.log('users');
    console.log('users');
    console.log('users');
    console.log(users);
    console.log('users');
    console.log('users');
    console.log('users');
    console.log('users');
    console.log('users');

full = full.replace('xxxxx',users[0].author);
    const fs = require("fs");   
    
fs.appendFileSync(name_file,full);


    
     for(let i=0; i < users.length; i++){   
//       if (users[i].points == 0)
//       { 



//      }
//      else 
        {
                     
            let notfull;
            var d = new Date(); // Today!
            d.setDate(d.getDate()-num_day); // Yesterday!
            d = d.toJSON().split("T")[0];
                d = d.replace(/-/gi, '');

    //  d = d.replace('xxxxx', users[1].authors);
                             
            //        title = users[i].title.replace(/[^a-zа-яё0-9\s]/gi, ' ');

            console.log('|',i+1,'|',users[i].author,'|',users[i].comments,'|',users[i].posts,'|',users[i].points,'|');

            let z = Number(i + 1);

            //notfull = users[1].authors+users[1].authors+users[1].authors+'\n|'+z+'|'+users[i].author+'|'+users[i].comments+'|'+users[i].posts+'|'+users[i].points+'|';
            notfull = '\n|'+z+'|'+users[i].author+'|'+users[i].comments+'|'+users[i].posts+'|'+users[i].points+'|';
let notfull_report;
                        notfull_report = '<tr><td>'+users[i].author+'</td><td>'+users[i].comments+'</td><td>'+users[i].posts+'</td><td>'+users[i].points+'</td></tr>';

          
          
    //          const fs = require("fs");            
        fs.appendFileSync(name_file,notfull);
                fs.appendFileSync(name_file_report,notfull_report);

         }

  //    console.log(notfull);

    }
    
      //   console.log('|',i+1,'|',users[i].author,'|','<a href="'+ users[i].url+'">' + title + '</a>','|', users[i].comments,'|', users[i].length,'|');
      
    //  + '\n|'+i+1+'|'+users[i].author+'|'+'<a href="'+ users[i].url+'">' + title + '</a>'+'|'+ users[i].comments+'|'+ users[i].length+'|\n' 

    //console.log(notfull);
      //    const fs = require("fs");            
            let notfull;
            var d = new Date(); // Today!
            d.setDate(d.getDate()-num_day); // Yesterday!
            d = d.toJSON().split("T")[0];
                d = d.replace(/-/gi, '');   
//accounts = accounts.replace(/\n\n/gi, '\n');
let accounts_com = fs.readFileSync('/root/rank/club/User-Activity-Rank/report/com'+bd_name+d+'.txt').toString() 
accounts_com = accounts_com.replace(/\n\n/gi, '\n');

let accounts_post = fs.readFileSync('/root/rank/club/User-Activity-Rank/report/post'+bd_name+d+'.txt').toString()   
accounts_post = accounts_post.replace(/\n\n/gi, '\n');

full = `

<h2>Analysis of comments and posts, on the basis of which the overall rating is built:</h2>

List of participants by number of written comments:

` + accounts_com + `  

List of posts sorted by length:

` + accounts_post + `


Welcome to the User Activity Rating Club: 
https://steemit.com/hive-153018/@alexmove.witness/i-invity-you-to-join-user-activity-rating-club     
    
NodeJs Scripts:
https://github.com/Alexmovelove/User-Activity-Rank.git

Instructions for setting User Activity Rating:
https://steemit.com/steemit/@alexmove.witness/start-daily-rank-from-user-activity-rating-club

Thanks for attention!
`


      fs.appendFileSync(name_file,full);
        
    
});
 
connection.end();

Script fulllistpost.js


const mysql = require("mysql2");
const steem = require('steem');
const fs = require("fs");            
  
var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;
let wifkey = settings.wifkey;
let votey = settings.account;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}



    //for (var yyy = 0; yyy < 2; yyy++)
    
    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    

let accounts = fs.readFileSync("/root/rank/club/User-Activity-Rank/"+bd_name+d+'.txt').toString();

//accounts = accounts.replace(/\n\n/gi, '\n');
let accounts_com = fs.readFileSync('/root/rank/club/User-Activity-Rank/report/com'+bd_name+d+'.txt').toString() 
accounts_com = accounts_com.replace(/\n\n/gi, '\n');
        
console.log(accounts);

let permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();

console.log(permlink);
let title = "Users Activity Rank Club. Daily Rating: " + d;


steem.broadcast.comment(
    wifkey, // Your posting wif
    '', // Parent Author
    //'hive-171319', // Parent Permlink
    'alexmove', // Parent Permlink
    votey,
    permlink, // Your post permlink
    title, // Title
    accounts, // Body   
        { tags: ['steem','steemit','ukraine','js','games'], app: 'ganeshaway' }, // Json Metadata
        function(err, result) {
            console.log(err, result)});



Script install.js

const mysql = require("mysql2");
  

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}


let formula;


let mytable = 'c1810';
let mytable_day = 'a1810';


const sql = `SELECT * FROM authors ORDER BY points DESC`    ;
connection.query(sql,  function(err, results) {
    if(err) console.log(err);
    const users = results;
     for(let i=0; i < users.length; i++){
                               
                   if (users[i].count>0) {
                        formula = (users.length - i)/10;
                    //  console.log(users[i].count);

                   } else { formula = 0;
                 //  console.log('sdfsdfs');
                   }

        
      console.log('|',i+1,'|',users[i].name,'|',users[i].points,'|');

    }
});
 
connection.end();

Script listcom.js



const mysql = require("mysql2");
    
var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}
const connection = mysql.createConnection(config);


let formula;

    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    
let mytable = 'c'+d;
let name_file = '/root/rank/club/User-Activity-Rank/report/com'+bd_name+d+".txt";


    let full = `
|N|acc|com.|balls|
------------|-------------|------------|------------|`;


const fs = require("fs");            
//fs.appendFileSync("..\\com"+d+".txt",full);
fs.appendFileSync(name_file,full);


const sql = `SELECT * FROM ${mytable} ORDER BY points DESC` ;
connection.query(sql,  function(err, results) {
    console.log(results);
    if(err) console.log(err);
    const users = results;
    
        console.log(users.length);
    console.log(users.length);
    console.log(users.length);
    
     for(let i=0; i < users.length; i++){
    //                if (users[i].points == 0)
    //   { 

    //  }
    //  else 
        {
            
let notfull;
        var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
                     
           //if (users[i].count>0) 
           {
    
            formula = (users.length - i)/10;
                    //  console.log(users[i].count);

                   } 
                   //else { formula = 0;
                 //  console.log('sdfsdfs');
                   //}

    
        console.log('|',i+1,'|',users[i].author,'|', users[i].count,'|',users[i].points,'|');
        
   let z = Number(i + 1);
   
   notfull = '\n|'+z+'|'+users[i].author+'|'+ users[i].count+'|'+ users[i].points+'|\n';
  
const fs = require("fs");            
//fs.appendFileSync("..\\com"+d+".txt",notfull);
fs.appendFileSync(name_file,notfull);


           }
    }
     


    
      const fs = require("fs");            
    //  fs.appendFileSync("..\\report"+d+".txt",full);
    //  fs.appendFileSync("com"+bd_name+d+".txt",full);
        
        
});
 
connection.end();

Script listday.js

const mysql = require("mysql2");
  

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}
const connection = mysql.createConnection(config);

let formula;


    var d = new Date(); // Today!
    d.setDate(d.getDate()-1); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;


const sql = `SELECT * FROM ${mytable} ORDER BY points DESC` ;
connection.query(sql,  function(err, results) {
    if(err) console.log(err);
    const users = results;
     for(let i=0; i < users.length; i++){
                               
                   if (users[i].count>0) {
                        formula = (users.length - i)/10;
                    //  console.log(users[i].count);

                   } else { formula = 0;
                 //  console.log('sdfsdfs');
                   }

        
      console.log('|',i+1,'|',users[i].author,'|',users[i].comments,'|',users[i].posts  ,'|',users[i].points,'|');

    }
});
 
connection.end();

Script listpost.js


    const mysql = require("mysql2");
      
    var settings = require('./config.js');

    let body3R = '';
    let num_day = settings.num_day;
    let bd_name = settings.bd_name;
    let hive_name = settings.hive_name;
    let url_post = settings.url_post;
    let password_mysql = settings.password_mysql;
    let user_mysql = settings.user_mysql;
    let title_name = settings.title_name;
    let image_list = settings.image_list;

    config = {
      host: "localhost",
      user: user_mysql,
      database: bd_name,
      password: password_mysql
    }
    const connection = mysql.createConnection(config);

    let formula;

        var d = new Date(); // Today!
        d.setDate(d.getDate()-num_day); // Yesterday!
        d = d.toJSON().split("T")[0];
        d = d.replace(/-/gi, '');
        

    let mytable = 'p'+d;
    let name_file = '/root/rank/club/User-Activity-Rank/report/post'+bd_name+d+".txt";


        let full = `
    |N|acc|title|comm.|length|
    ------------|-------------|------------|-------------|----|`;


    const fs = require("fs");            
    fs.appendFileSync(name_file,full);




    const sql = `SELECT * FROM ${mytable} ORDER BY length DESC` ;
    console.log(sql);
    connection.query(sql,  function(err, results) {
        if(err) console.log(err);
        const users = results;
        
         for(let i=1; i < users.length; i++){   
    let notfull;
            var d = new Date(); // Today!
        d.setDate(d.getDate()-num_day); // Yesterday!
        d = d.toJSON().split("T")[0];
        d = d.replace(/-/gi, '');
                         
                      // if (users[i].count>0)
                           {
                            formula = (users.length - i)/10;
                        //  console.log(users[i].count);

                       } 
                       
                       //else { formula = 0;
                     //  console.log('sdfsdfs');
                      // }
      

                title = users[i].title.replace(/[^a-zа-яё0-9\s]/gi, ' ');

            console.log('|',i+1,'|',users[i].author,'|','<a href="'+ users[i].url+'">' + title + '</a>','|', users[i].comments,'|', users[i].length,'|',users[i].percent,'|');
            
       let z = Number(i + 1);
       notfull = '\n|'+z+'|'+users[i].author+'|'+'<a href="'+ users[i].url+'">' + title + '</a>'+'|'+ users[i].comments+'|'+ users[i].length+'|\n';
      
    fs.appendFileSync(name_file,notfull);


      //    console.log(notfull);

        }
        
          //   console.log('|',i+1,'|',users[i].author,'|','<a href="'+ users[i].url+'">' + title + '</a>','|', users[i].comments,'|', users[i].length,'|');
          
        //  + '\n|'+i+1+'|'+users[i].author+'|'+'<a href="'+ users[i].url+'">' + title + '</a>'+'|'+ users[i].comments+'|'+ users[i].length+'|\n' 

        //console.log(notfull);
        
        

    full = `\n
    `


        
          fs.appendFileSync(name_file,full);
            
            
    });
     
    connection.end();

Script sortcom.js

const mysql = require("mysql2");
  

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}
const connection = mysql.createConnection(config);



let formula;

    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;


  
let sql3 = `create table if not exists ${mytable}(
  id int primary key auto_increment,
  author varchar(255) not null,
  comments float not null,
  posts float not null,
  points float not null 
  )`;

 
     connection.query(sql3,function(err, results) {
            if(err) console.log(err);
            });
            
            
            
            
const sql = `SELECT * FROM ${mytable_c} ORDER BY count DESC`  ;
connection.query(sql,  function(err, results) {
    if(err) console.log(err);
    const users = results;
     for(let i=0; i < users.length; i++){
                               
                   if (users[i].count>0) {
                        formula = (users.length - i)/10;
                    //  console.log(users[i].count);

                   } else { formula = 0;
                 //  console.log('sdfsdfs');
                   }

                   
const connection = mysql.createConnection(config);
            const sql = `UPDATE ${mytable_c} SET points='${formula}' WHERE author='${users[i].author}' LIMIT 1000`;
            console.log(sql);
            
            
        //  const sql = `UPDATE ${mytable} SET points=${formula} WHERE id=${users[i].id}`;


            connection.query(sql,function(err, results) {
            if(err) console.log(err);
            });
            
            const sql12 = `UPDATE ${mytable} SET comments=${formula} WHERE author='${users[i].author}'`;
            console.log(sql12);
            
            connection.query(sql12,function(err, results) {
            if(err) console.log(err);
            //console.log(results);
            });
            
            
        //console.log (users[i].id);
            
connection.end();

      console.log('|',i+1,'|',users[i].author,'|',users[i].count,'|',formula,'|');

    }
});
 
connection.end();

Script listpost.js

const mysql = require("mysql2");
  

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}
const connection = mysql.createConnection(config);



    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;


const sql = `SELECT * FROM ${mytable_p} ORDER BY length DESC` ;
connection.query(sql,  function(err, results) {
      //  console.log(results);

    if(err) console.log(err);
    const users = results;
    console.log(users);
    
    for(let i=0; i < users.length; i++){
               let formula = (users.length - i)/10;

const connection = mysql.createConnection(config);
            const sql = `UPDATE ${mytable_p} SET points=${formula} WHERE url='${users[i].url}'`;
            
            connection.query(sql,function(err, results) {
            if(err) console.log(err);
           // console.log(results);
            });
            
            const sql12 = `UPDATE ${mytable} SET posts=${formula} WHERE
            author='${users[i].author}'`;
            
            connection.query(sql12,function(err, results) {
            if(err) console.log(err);
            //console.log(results);
            });
            
connection.end();

      console.log('|',i+1,'|',users[i].author,'|','<a href="',users[i].url,'">',users[i].length,'</a>','|',formula,'|');
     // console.log('|',i+1,'|',users[i].author,'|',users[i].upvotes);
     // console.log('|',i+1,'|',users[i].author,'|',users[i].comments);

    }
});
 
connection.end();

Script sum.js

const mysql = require("mysql2");
  

var settings = require('./config.js');

let body3R = '';
let num_day = settings.num_day;
let bd_name = settings.bd_name;
let hive_name = settings.hive_name;
let url_post = settings.url_post;
let password_mysql = settings.password_mysql;
let user_mysql = settings.user_mysql;
let title_name = settings.title_name;
let image_list = settings.image_list;

config = {
  host: "localhost",
  user: user_mysql,
  database: bd_name,
  password: password_mysql
}
const connection = mysql.createConnection(config);




    var d = new Date(); // Today!
    d.setDate(d.getDate()-num_day); // Yesterday!
    d = d.toJSON().split("T")[0];
    d = d.replace(/-/gi, '');
    console.log(d);   

let mytable_p = 'p'+d;
let mytable_c = 'c'+d;
let mytable = 'a'+d;



const sql = `SELECT * FROM ${mytable}`  ;
connection.query(sql,  function(err, results) {
    if(err) console.log(err);
    const users = results;
    console.log(users);
    for(let i=0; i < users.length; i++){
               let formula = (users.length - i)/10;

const connection = mysql.createConnection(config);

let count_day = users[i].comments + users[i].posts;

            const sql12 = `UPDATE ${mytable} SET points=comments+posts WHERE id=${users[i].id}`;
            
            connection.query(sql12,function(err, results) {
            if(err) console.log(err);
            //console.log(results);
            });
            
//connection.end();

      console.log('|',i+1,'|',users[i].author,'|','<a href="',users[i].url,'">',users[i].length,'</a>','|',formula,'|');
     // console.log('|',i+1,'|',users[i].author,'|',users[i].upvotes);
     // console.log('|',i+1,'|',users[i].author,'|',users[i].comments);

    }
});
 
connection.end();


Thank you for your attention.
Have a nide day!

Coin Marketplace

STEEM 0.28
TRX 0.23
JST 0.041
BTC 95633.77
ETH 3618.77
SBD 3.89