Development of automation for checking uniqueness in STEEMIT. Part 4. Transfer to Heroku. STEEM-BRU RANK POST

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

Мне удалось добится значительных результатов!
Полностью настроенная система для STEEM-GARDEN сейчас на тестировании.

image.png

Я создам ту же систему для STEEM-FAMILY и посмотрю насколько легким будет перенос и тестирование.

Но пока мне хочется настроить систему для RANK BRU, это скорее мое большое желание перенести RANK POST и потренироваться.

Это по поводу уникальности:

heroku restart
git add . && git commit -m "update pkg-lock" && git push heroku master
heroku logs --tail
https://dashboard.heroku.com/apps/gardenweb0301/scheduler

$ curl -n -X DELETE https://api.heroku.com/apps/gardenweb0301/dynos -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: Bearer 515658a4-a9d7-42b0-aaa1-fc669d69e0ba"

heroku auth:token

$ curl -n -X DELETE https://api.heroku.com/apps/gardenweb0301/dynos -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: Bearer 87e38a9f-070b-4577-975b-0af7145d7d97"

STEEM-BRU RANK POST - transfer to server

По собственной инструкции: https://steemit.com/hive-171319/@alexmove/development-of-automation-for-checking-uniqueness-in-steemit-part-2-heroku-and-nodejs-and-cleardb-mysql

cd brurankweb
git init
heroku login
heroku create

heroku rename brurankweb1501

express --view=pug brurankweb
npm install
set DEBUG=myapp:* & npm start

http://localhost:3000/

npm start

git add . && git commit -m "update pkg-lock" && git push heroku master
heroku logs --tail

heroku addons:create cleardb:ignite
heroku config | findstr CLEARDB

CLEARDB_DATABASE_URL: mysql://b4cf344f289b51:[email protected]/heroku_e94e2e855574b7d?reconnect=true

heroku config | findstr CLEARDB

https://brurankweb1501.herokuapp.com/create

npm i mysql2
npm i steem
npm i mysql2

Работает!!!

heroku logs --tail

heroku authorizations:create

curl -n -X DELETE https://api.heroku.com/apps/gardenweb0301/dynos -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: Bearer xxx-1c85-4084-a257-2543e8ded044"

https://dashboard.heroku.com/apps/brurankweb1501/scheduler

https://www.it-roy-ru.com/ru/node.js/ispolzovanie-planirovshika-heroku-s-node.js/1070556844/amp/

http://www.modeo.co/blog/2015/1/8/heroku-scheduler-with-nodejs-tutorial

https://console.cron-job.org/jobs

https://ru.stackoverflow.com/questions/1254245/%D0%9A%D0%B0%D0%BA-%D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%B8%D1%82%D1%8C-%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D0%B5-%D0%B2-%D0%BF%D0%B5%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D1%83%D1%8E-%D1%81-mysql

if(connection.state === 'disconnected'){

 const connection = mysql.createConnection({
    host: "us-cdbr-east-05.cleardb.net",
    user: "b4cf344f289b51",
    database: "heroku_e94e2e855574b7d",
    password: "dc0e2e73"
    });

}

https://overcoder.net/q/738573/%D0%BE%D1%82%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5-%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85-%D0%B2-%D1%84%D0%B0%D0%B9%D0%BB%D0%B5-html-js-%D1%81-%D0%B8%D1%81%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5%D0%BC-nodejs-%D0%B8%D0%B7-%D0%B1%D0%B0%D0%B7%D1%8B-%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85-mysql

Нужно переделывать логику скриптов. На данный момент есть простой способ прикрутить проверку, есть ли такая запись уже в базе, чтобы снова не открывать соединение с базой (у меня именно с этим сейчас наибольшие проблемы).

Итак, значит надо записать данные в переменную.

https://www.itgid.info/unit/nodejs?unit=nodejs-11
https://www.itgid.info/course/nodejs

Заработало!

Достаточно было лишь вынести подключение к БД в самый верх - вначале скрипта роутера.

Заработало!

var express = require('express');
var router = express.Router();
                        
let attention =  "VERY";
     console.log(attention);   
   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({
host: "us-cdbr-east-05.cleardb.net",
user: "b4cf344f289b51",
database: "heroku_e94e2e855574b7d",
password: "dc0e2e73"
});

/* GET users listing. */
router.get('/', function(req, res, next) {



const fs = require("fs");
const steem = require('steem');
let body3R = '';
let num_day = 1;

                        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 = 'poststest';
let mytable = 'p'+d;

////let mytable = 'p20211208';
let mytable_p = mytable;
// mytable_p = 'p20211208';

 // const sql_posts = `SELECT * FROM mytable`;
  const sql_posts = `SELECT * FROM heroku_e94e2e855574b7d.p20220114 LIMIT 0,1000`;
           //    console.log(sql_posts); 

  connection.query(sql_posts,  function(err, results) {
              if(err) console.log(err);
              attention = results.join
 });

               console.log(attention); 
            


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


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

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, 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)`;



 connection.query(sql, function(err, results) {
            console.log("TWO");
            console.log("TWO");
            console.log("TWO");
            console.log("TWO");
            console.log("TWO");
            console.log("TWO");
;
            console.log(attention);       console.log(attention);       console.log(attention);       console.log(attention);       console.log(attention);       console.log(attention);       console.log(attention);       console.log(attention);
            
            
 if(err) console.log(err);
  console.log(results);
            });     
// connection.end();

//https://steemit.com/hive-171319/@alexmove/the-word-game-post-2


//accounts.forEach(function (element,i,array)
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],3, function(err, result) {
      console.log('yyy');
      console.log(yyy);

       if (result)
       {
           
    

        var i, len = result.length;
                    for (i = 0; i < len; i++) 
                    {
                                                    
                       var raw = result[i];
                        console.log(raw.author);
                        console.log(raw.created);

                        let upvote = raw.active_votes.length-1;
                     
                            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)&& (raw.category === 'hive-171319'))
                          // if (input.indexOf(d) !== -1)

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


                                      //  const mysql = require("mysql2");
                                      
        


/*   const connection = mysql.createConnection({
        host: "us-cdbr-east-05.cleardb.net",
        user: "b4cf344f289b51",
        database: "heroku_e94e2e855574b7d",
        password: "dc0e2e73"
        });
        
        */
                    //connection.on('error', function() {});

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

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


                        }
            }


    }
        });
}

    });
    
    
    });

module.exports = router;
Sort:  
 4 years ago (edited)

Happy-people-walking-and-having-fun-in-winter-park.png

Coin Marketplace

STEEM 0.12
TRX 0.34
JST 0.032
BTC 121409.26
ETH 4345.39
USDT 1.00
SBD 0.78