Skip to content

Commit c09ccc9

Browse files
authored
Add step to stats update workflow to fetch Twitter followers (#1952)
1 parent ab5fc3a commit c09ccc9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/update-stats.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ data.stars = github.stargazers_count;
4747
data.followers.mastodon = mastodon.followers_count;
4848
data.followers.bluesky = bluesky.followersCount;
4949

50+
// Fetch the latest Astro Twitter followers count from the Twitter API.
51+
// Conditional because it’s the one API that needs authorization.
52+
if (process.env.TWITTER_BEARER_TOKEN) {
53+
const twitter = z
54+
.object({
55+
data: z.object({
56+
public_metrics: z.object({ followers_count: z.number() }),
57+
}),
58+
})
59+
.parse(
60+
await fetch(
61+
'https://api.x.com/2/users/by/username/astrodotbuild?user.fields=public_metrics',
62+
{ headers: { Authorization: `Bearer ${process.env.TWITTER_BEARER_TOKEN}` } },
63+
).then((res) => res.json()),
64+
);
65+
console.log(`✔︎ Twitter followers: ${twitter.data.public_metrics.followers_count}`);
66+
data.followers.twitter = twitter.data.public_metrics.followers_count;
67+
}
68+
5069
// Write updated stats back to src/data/stats.json.
5170
console.log('‣ Writing updated stats to src/data/stats.json...');
5271
await writeFile('src/data/stats.json', JSON.stringify(data, null, '\t'));

0 commit comments

Comments
 (0)