Files
docker-compose-hatthieves/development/node/follow/follow.js
Your Name a25aa972ca node
2020-05-28 10:33:55 +00:00

61 líneas
2.6 KiB
JavaScript

'use strict'
const requestsync = require('sync-request')
/*let body = requestsync('GET', 'https://social.hatthieves.es/api/v1/instance/peers'),
urls = JSON.parse(body.getBody())*/
//for (let url of urls) {
let url = 'social.hatthieves.es',
count = 100
// try {
let actors,
followed = [],
body
do {
let id = actors && actors.length > 0 ? actors[actors.length - 1].id : ''
body = requestsync('GET', 'https://ale:pleroma.@' + 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 && body.statusCode === 200)
actors = []
do {
let id = actors && actors.length > 0 ? actors[actors.length - 1].id : ''
body = requestsync('GET', 'https://' + url + '/api/v1/timelines/public?max_id=' + id + '&only_media=false&count=20&with_muted=true')
try {
actors = JSON.parse(body.getBody())
if (actors && actors.length > 0) {
for (let a of actors) {
if (a && a.user && a.user.id && !followed.some(f => f === a.user.id)) {
requestsync('POST', 'https://ale:pleroma.@social.hatthieves.es/api/v1/accounts/' + a.user.id + '/follow')
if (a.in_reply_to_user_id && !followed.some(f => f === a.in_reply_to_user_id)) {
requestsync('POST', 'https://ale:pleroma.@social.hatthieves.es/api/v1/accounts/' + a.in_reply_to_user_id + '/follow')
followed.push(a.in_reply_to_user_id)
console.log('following: ' + a.in_reply_to_user_id)
}
followed.push(a.user.id)
console.log('following: ' + a.user.screen_name)
}
}
}
} catch (e) {
console.log(e)
}
console.log(url + ' following: ' + followed.length)
} while (actors && actors.length >= 20 && body.statusCode === 200)
/* } catch (e) {
console.log(e)
}*/
//}