Public
Script
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { mastodon$sumStats } from "https://esm.town/v/jaandrle/mastodon$sumStats";
import { mastodon$fetchInstanceStats } from "https://esm.town/v/jaandrle/mastodon$fetchInstanceStats";
// https://api.val.town/eval/@jaandrle.mastodon$collectStats(@jaandrle.mastodon$instances_cz, 1)
export async function mastodon$collectStats(instances, weeks = 1) {
const data = await Promise.all(
instances.map(mastodon$fetchInstanceStats)
);
return data
.filter(({ stats }) => Boolean(stats) && Array.isArray(stats))
.map(({ instance, stats }) =>
Object.assign(
{ instance },
mastodon$sumStats(stats.slice(0, weeks + 1))
)
);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023