+23
-17
src/toplikes.ts
+23
-17
src/toplikes.ts
···
1
-
import { Client, simpleFetchHandler } from '@atcute/client';
2
-
import { AppBskyFeedPost } from '@atcute/bluesky';
3
-
import { parseResourceUri } from '@atcute/lexicons';
4
-
import fs from 'fs';
5
-
import 'dotenv/config';
1
+
import { Client, simpleFetchHandler } from "@atcute/client";
2
+
import { AppBskyFeedPost } from "@atcute/bluesky";
3
+
import { parseResourceUri } from "@atcute/lexicons";
4
+
import fs from "fs";
5
+
import "dotenv/config";
6
6
7
7
const client = new Client({
8
-
handler: simpleFetchHandler({ service: 'https://public.api.bsky.app' }),
8
+
handler: simpleFetchHandler({ service: "https://public.api.bsky.app" }),
9
9
});
10
10
11
-
async function getLikedPosts(cursor: string | undefined = undefined, posts: AppBskyFeedPost.Main[] = []): Promise<AppBskyFeedPost.Main[]> {
12
-
const response = await client.get('app.bsky.feed.getAuthorFeed', {
11
+
async 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", {
13
16
params: {
14
17
actor: process.env.DID,
15
18
filter: "posts_no_replies",
16
-
cursor
17
-
}
19
+
cursor,
20
+
},
18
21
});
19
22
20
23
if (!response.ok) {
21
-
console.log(response)
24
+
console.log(response);
22
25
return [];
23
26
}
24
27
···
29
32
}
30
33
31
34
if (response.data.cursor) {
32
-
return getLikedPosts(response.data.cursor, posts)
35
+
return getLikedPosts(response.data.cursor, posts);
33
36
}
34
37
35
38
return posts;
···
38
41
async function main() {
39
42
const posts = await getLikedPosts();
40
43
41
-
posts.sort((a, b) => b.post.likeCount - a.post.likeCount)
44
+
posts.sort((a, b) => b.post.likeCount - a.post.likeCount);
42
45
43
-
fs.writeFileSync('dist/toplikes.md', 'Post | likes');
44
-
fs.appendFileSync('dist/toplikes.md', '\n-----|------');
46
+
fs.writeFileSync("dist/toplikes.md", "Post | likes");
47
+
fs.appendFileSync("dist/toplikes.md", "\n-----|------");
45
48
46
49
for (const post of posts) {
47
50
const uri = parseResourceUri(post.post.uri);
48
51
49
52
if (!uri.ok) continue;
50
53
51
-
fs.appendFileSync('dist/toplikes.md', `\nhttps://bsky.app/profile/${uri.value.repo}/post/${uri.value.rkey} | ${post.post.likeCount}`);
54
+
fs.appendFileSync(
55
+
"dist/toplikes.md",
56
+
`\nhttps://bsky.app/profile/${uri.value.repo}/post/${uri.value.rkey} | ${post.post.likeCount}`,
57
+
);
52
58
}
53
59
}
54
60
55
-
main()
61
+
main();
+25
-17
src/whodoilike.ts
+25
-17
src/whodoilike.ts
···
1
-
import { Client, CredentialManager } from '@atcute/client';
2
-
import { AppBskyFeedDefs } from '@atcute/bluesky';
3
-
import fs from 'fs';
4
-
import 'dotenv/config';
1
+
import { Client, CredentialManager } from "@atcute/client";
2
+
import { AppBskyFeedDefs } from "@atcute/bluesky";
3
+
import fs from "fs";
4
+
import "dotenv/config";
5
5
6
-
async function getLikedPosts(cursor: string | undefined = undefined, posts: AppBskyFeedDefs.FeedViewPost[] = []): Promise<AppBskyFeedDefs.FeedViewPost[]> {
7
-
const response = await rpc.get('app.bsky.feed.getActorLikes', {
6
+
async function getLikedPosts(
7
+
cursor: string | undefined = undefined,
8
+
posts: AppBskyFeedDefs.FeedViewPost[] = [],
9
+
): Promise<AppBskyFeedDefs.FeedViewPost[]> {
10
+
const response = await rpc.get("app.bsky.feed.getActorLikes", {
8
11
params: {
9
12
actor: process.env.DID,
10
-
cursor
11
-
}
13
+
cursor,
14
+
},
12
15
});
13
16
14
17
if (!response.ok) {
15
-
console.log(response)
18
+
console.log(response);
16
19
return [];
17
20
}
18
21
···
23
26
posts.push(feedItem);
24
27
}
25
28
26
-
console.log(`added ${posts.length} posts`)
29
+
console.log(`added ${posts.length} posts`);
27
30
// console.log(response.data.cursor);
28
31
29
32
// maybe its a skill issue but this IRs, adding the length check helps stop that
···
31
34
return posts;
32
35
}
33
36
34
-
return getLikedPosts(response.data.cursor, posts)
37
+
return getLikedPosts(response.data.cursor, posts);
35
38
}
36
39
37
40
async function main() {
38
41
const posts = await getLikedPosts();
39
42
40
-
fs.writeFileSync('dist/whodoilike.md', 'DID | handle | times likes');
41
-
fs.appendFileSync('dist/whodoilike.md', '\n----|------|-----------');
43
+
fs.writeFileSync("dist/whodoilike.md", "DID | handle | times likes");
44
+
fs.appendFileSync("dist/whodoilike.md", "\n----|------|-----------");
42
45
43
46
const didToLikes = new Map();
44
47
for (const post of posts) {
···
48
51
let didsLikes = didToLikes.get(did).likes;
49
52
didToLikes.set(did, { handle, likes: didsLikes + 1 });
50
53
} else {
51
-
didToLikes.set(did, { handle, likes: 1 })
54
+
didToLikes.set(did, { handle, likes: 1 });
52
55
}
53
56
}
54
57
55
-
var descDidToLikes = new Map([...didToLikes.entries()].sort((a, b) => b[1].likes - a[1].likes));
58
+
var descDidToLikes = new Map(
59
+
[...didToLikes.entries()].sort((a, b) => b[1].likes - a[1].likes),
60
+
);
56
61
57
62
let output = "Rank | Handle | Times Liked\n----|------|----------";
58
63
let i = 1;
···
67
72
// hoist me pls
68
73
const manager = new CredentialManager({ service: process.env.PDS });
69
74
const rpc = new Client({ handler: manager });
70
-
await manager.login({ identifier: process.env.DID, password: process.env.PASSWORD });
75
+
await manager.login({
76
+
identifier: process.env.DID,
77
+
password: process.env.PASSWORD,
78
+
});
71
79
72
80
const mydid = "";
73
81
74
-
main()
82
+
main();