this repo has no description
at main 61 lines 1.5 kB view raw
1import { Client, simpleFetchHandler } from "@atcute/client"; 2import { AppBskyFeedPost } from "@atcute/bluesky"; 3import { parseResourceUri } from "@atcute/lexicons"; 4import fs from "fs"; 5import "dotenv/config"; 6 7const client = new Client({ 8 handler: simpleFetchHandler({ service: "https://public.api.bsky.app" }), 9}); 10 11async function getLikedPosts( 12 cursor: string | undefined = undefined, 13 posts: AppBskyFeedPost.Main[] = [], 14): Promise<AppBskyFeedPost.Main[]> { 15 const response = await client.get("app.bsky.feed.getAuthorFeed", { 16 params: { 17 actor: process.env.DID, 18 filter: "posts_no_replies", 19 cursor, 20 }, 21 }); 22 23 if (!response.ok) { 24 console.log(response); 25 return []; 26 } 27 28 for (const feedItem of response.data.feed) { 29 if (feedItem.post.author.did != process.env.DID) continue; 30 31 posts.push(feedItem); 32 } 33 34 if (response.data.cursor) { 35 return getLikedPosts(response.data.cursor, posts); 36 } 37 38 return posts; 39} 40 41async function main() { 42 const posts = await getLikedPosts(); 43 44 posts.sort((a, b) => b.post.likeCount - a.post.likeCount); 45 46 fs.writeFileSync("dist/toplikes.md", "Post | likes"); 47 fs.appendFileSync("dist/toplikes.md", "\n-----|------"); 48 49 for (const post of posts) { 50 const uri = parseResourceUri(post.post.uri); 51 52 if (!uri.ok) continue; 53 54 fs.appendFileSync( 55 "dist/toplikes.md", 56 `\nhttps://bsky.app/profile/${uri.value.repo}/post/${uri.value.rkey} | ${post.post.likeCount}`, 57 ); 58 } 59} 60 61main();