Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ======================= Коннект ==========================
- //const GOLOSNODE = "ws://localhost:9090"
- //const GOLOSNODE = "wss://api.golos.cf"; //нода @vik
- const GOLOSNODE = "wss://ws.golos.io"; //ropox
- // Подключение JavaScript библиотеки для работы c API голоса
- const golos = require('golos-js');
- // Указываем ноду, к которой будет подключен скрипт
- golos.config.set('websocket', GOLOSNODE);
- // =====================================================================
- //#######################################################################
- function findActiveVotes (author , permlink) {
- return golos.api.getActiveVotes(author, permlink, function(err, result) {
- if(err){console.log(err);}
- });
- }
- //#######################################################################
- function checkAccount (voter) {
- // let names = [voter];
- return golos.api.getAccounts(voter, function(err, result) {
- if(err){console.log(err);}
- });
- }
- //#######################################################################
- function ReceiveBlog (author,permlink) {
- return golos.api.getContent(author, permlink, function(err, result) {
- if(err){console.log(err);}
- });
- }
- //#######################################################################
- function findblogs (coments) {
- return new Promise(function(resolve, reject) {
- let blogdata = [];
- for (z=0;z < coments.length;z++ ){
- blogdata.push(ReceiveBlog(coments[z].blogauthor,coments[z].bloglink))
- if (z == coments.length - 1) {
- resolve(Promise.all(blogdata))
- }
- }
- })
- }
- function findWeeklyPosts (blogs) {
- return new Promise(function(resolve, reject) {
- let blogdata = [];
- for (z=0;z < blogs.length;z++ ){
- let blogcreated = new Date(new Date(blogs[z].created).getTime() + (3*1000*60*60));
- if ((blogcreated > lastMonday) && (blogcreated < lastSunday)) {
- let blogurl = blogdata.map(a => a.url);
- if (blogurl.includes(blogs[z].url)) {
- continue;
- }
- else {
- fill = {
- author: blogs[z].author,
- permlink: blogs[z].permlink,
- children: blogs[z].children,
- bloglength: blogs[z].body.length,
- author_reputation: blogs[z].author_reputation,
- url: blogs[z].url,
- title: blogs[z].title
- }
- blogdata.push(fill);
- }
- }
- if (z == blogs.length - 1) {
- resolve(Promise.all(blogdata))
- }
- }
- })
- }
- function findVotes (blogs) {
- return new Promise(function(resolve, reject) {
- let blogdata = [];
- for (z=0;z < blogs.length;z++ ){
- let activevotes = findActiveVotes (blogs[z].author, blogs[z].permlink)
- fill = {
- post: blogs[z],
- activevotes: activevotes
- }
- blogdata.push(fill)
- if (z == blogs.length - 1) {
- resolve(blogdata);
- }
- }
- })
- }
- async function getavrhash(activevotes) {
- let not_bot = [];
- let voters = activevotes.map(a => a.voter)
- let vt = await checkAccount(voters);
- for (let v of vt) {
- if ((v.proxy == '') && (v.recovery_account == 'golosio') && !(blacklistvoters.includes(v.name)) && (parseInt(v.reputation) > 9999999999) ) {
- not_bot += v.name;
- };
- }
- return (not_bot);
- };
- //let not_bot_array = activevotes.filter(function(obj) { return notbot.indexOf(obj.voter) == -1; })
- const collectposts = new Promise(function(resolve, reject) {
- getlastweekcomments
- .then (function (result,err){
- console.log("Всего коментариев:",result.length)
- findblogs (result)
- .then (function (result,err){
- console.log("Всего постов с начала даты:",result.length)
- findWeeklyPosts (result)
- .then (function (result,err){
- console.log("Всего подходящих постов:", result.length);
- findVotes (result)
- .then (function (result,err){
- resolve(result)
- })
- .catch(err => {
- console.log("PROMISE Не удалось вычеслить findVotes")
- resolve(undefined)
- })
- })
- .catch(err => {
- console.log("PROMISE Не удалось вычеслить findWeeklyPosts")
- resolve(undefined)
- })
- })
- .catch(err => {
- console.log("PROMISE Не удалось вычеслить findblogs")
- resolve(undefined)
- })
- })
- .catch(err => {
- console.log("PROMISE Не удалось вычеслить getlastweekcomments")
- resolve(undefined)
- })
- })
- //############################################
- async function runBot() {
- let data = await collectposts
- //let activevotes = await findRealVotes (data)
- console.log(data [9])
- }
- runBot()
Advertisement
Add Comment
Please, Sign In to add comment