From f7cb2cbfce32f5ae01eee629680413681781bdc1 Mon Sep 17 00:00:00 2001 From: ale Date: Sat, 24 Aug 2019 12:31:08 +0000 Subject: [PATCH] count and preload --- follow.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/follow.js b/follow.js index 6236e77..5cd572a 100644 --- a/follow.js +++ b/follow.js @@ -4,7 +4,26 @@ const requestsync = require('sync-request'), try { let actors, - followed = [] + followed = [], + count = 100 + do { + let id = actors && actors.length > 0 ? actors[actors.length - 1].id : '', + body = requestsync('GET', url + '/api/v1/accounts/9lM7CeFGQNLWp38fgW/following?max_id=' + id + '&limit=' + count) + try { + actors = JSON.parse(body.getBody()) + if (actors && actors.length > 0) { + for (let a of actors) { + if (a && a.id && !followed.some(f => f === a.id)) { + followed.push(a.id) + } + } + } + } catch (e) { + console.log(e) + } + console.log('Loading users: ' + followed.length) + } while (actors && actors.length >= count) + actors = [] do { let id = actors && actors.length > 0 ? actors[actors.length - 1].id : '', body = requestsync('GET', url + '/api/statuses/networkpublic_timeline?max_id=' + id + '&only_media=false&count=20&with_muted=true') @@ -17,17 +36,17 @@ try { if (a.in_reply_to_user_id && !followed.some(f => f === a.in_reply_to_user_id)) { requestsync('POST', url + '/api/v1/accounts/' + a.in_reply_to_user_id + '/follow') followed.push(a.in_reply_to_user_id) - console.log('followed: ' + a.in_reply_to_user_id) + console.log('Following: ' + a.in_reply_to_user_id) } followed.push(a.user.id) - console.log('followed: ' + a.user.screen_name) + console.log('Following: ' + a.user.screen_name) } } } } catch (e) { console.log(e) } - console.log(url) + console.log('Following: ' + followed.length + ' accounts') } while (actors && actors.length >= 20) } catch (e) { console.log(e)