Skip to content

Instantly share code, notes, and snippets.

@yefim
Created December 16, 2022 09:01
Show Gist options
  • Save yefim/a1c37c68722145aadd9ad6d067e2464f to your computer and use it in GitHub Desktop.
Save yefim/a1c37c68722145aadd9ad6d067e2464f to your computer and use it in GitHub Desktop.
Adds total boost and favs counts to URLs
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