Created
December 16, 2022 09:01
-
-
Save yefim/a1c37c68722145aadd9ad6d067e2464f to your computer and use it in GitHub Desktop.
Adds total boost and favs counts to URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mastodon } from 'megalodon' | |
import _ from 'lodash'; | |
const client = new Mastodon('https://blumpus.com', 'YOUR_ACCESS_TOKEN'); | |
const clients = {}; | |
const main = async () => { | |
const res = await client.getHomeTimeline(); | |
const urls = res.data.map((r) => r.url).filter(Boolean).map((url) => { | |
const [id, _handle, ...parts] = url.split('/').reverse(); | |
const base = parts.reverse().join('/'); | |
return {base, id}; | |
}); | |
const numbers = await Promise.all(urls.map(({base, id}) => { | |
clients[base] = clients[base] || new Mastodon(base); | |
return clients[base].getStatus(id); | |
})); | |
console.log(numbers.map(({data}) => { | |
return _.pick(data, ['url', 'replies_count', 'reblogs_count', 'favourites_count']); | |
})); | |
} | |
main().catch((err) => { | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment