this repo has no description
at main 1.6 kB view raw
1import os 2 3from atproto import AtUri, Client 4 5# YOUR bluesky handle 6# Ex: user.bsky.social 7HANDLE: str = os.environ["HANDLE"] 8 9# YOUR bluesky password, or preferably an App Password (found in your client settings) 10# Ex: abcd-1234-efgh-5678 11PASSWORD: str = os.environ["PASSWORD"] 12 13SERVICE_PDS: str | None = os.environ.get("SERVICE_PDS") 14 15FEED_URI: str = os.environ["FEED_URI"] 16 17 18def main(): 19 client = Client(base_url=SERVICE_PDS) 20 client.login(HANDLE, PASSWORD) 21 22 if not client.me: 23 raise RuntimeError 24 25 uri = AtUri.from_str(FEED_URI) 26 if uri.collection != "app.bsky.feed.generator": 27 raise ValueError("URI not corresponding to a feed generator") 28 29 result = client.com.atproto.repo.get_record( 30 { 31 "repo": uri.hostname, 32 "collection": "app.bsky.feed.generator", 33 "rkey": uri.rkey, 34 } 35 ) 36 print(result) 37 38 result = client.app.bsky.feed.get_feed_generator({"feed": FEED_URI}) 39 print(result) 40 41 feed_result = client.app.bsky.feed.get_feed({"feed": FEED_URI, "limit": 30}) 42 print("✓ getFeed succeeded!") 43 print(f"\nRetrieved {len(feed_result.feed)} posts") 44 if feed_result.cursor: 45 print(f"Cursor: {feed_result.cursor}") 46 47 # Show first few posts with details 48 for idx, item in enumerate(feed_result.feed[:3]): 49 print(f"\n Post {idx + 1}:") 50 print(f" URI: {item.post.uri}") 51 print(f" Author: {item.post.author.handle}") 52 if item.post.record.text: 53 text = item.post.record.text[:100] 54 print(f" Text: '{text}...'") 55 56 57if __name__ == "__main__": 58 main()