-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_liked_posts_by_handle.py
59 lines (49 loc) · 1.73 KB
/
get_liked_posts_by_handle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import asyncio
import json
import sys
from more_itertools import chunked
from psychonaut.client import get_simple_client_session
from psychonaut.client.cursors import collect_cursored
from psychonaut.cli.util import clean_handle
from psychonaut.api.lexicons.com.atproto.identity.resolve_handle import ResolveHandleReq
from psychonaut.api.lexicons.com.atproto.repo.list_records import (
ListRecordsReq,
ListRecordsResp,
)
from psychonaut.api.lexicons.app.bsky.feed.get_posts import GetPostsReq
async def main(handle: str):
async with get_simple_client_session() as sess:
# Resolve the handle
response = await ResolveHandleReq(handle=handle).do_xrpc(sess)
print(response)
# Taking the DID from the resolved handle and get all likes by that person
likes = [
record
async for record in collect_cursored(
sess,
ListRecordsReq(
repo=response.did,
collection="app.bsky.feed.like",
limit=100,
),
ListRecordsResp,
"records",
)
]
uris = []
for record in likes:
print(json.dumps(record, indent=2))
uris.append(
# TODO: update after fixing ref bug that makes these Any types
record["value"]["subject"]["uri"]
)
# Get all liked posts
posts = [
post
for uri_chunk in chunked(uris, 25)
for post in await GetPostsReq(uris=uri_chunk).do_xrpc(sess)
]
print(json.dumps({"posts": posts}, indent=2))
if __name__ == "__main__":
handle = sys.argv[1]
asyncio.run(main(clean_handle(handle)))