at main 2.5 kB view raw
1#!/usr/bin/env -S uv run --script --quiet 2# /// script 3# requires-python = ">=3.12" 4# dependencies = ["atproto"] 5# /// 6""" 7publish feed records to bluesky. 8 9usage: 10 HANDLE=you.bsky.social PASSWORD=xxx FEED_HOSTNAME=your.domain ./scripts/publish.py 11 HANDLE=you.bsky.social PASSWORD=xxx FEED_HOSTNAME=your.domain ./scripts/publish.py --following 12 HANDLE=you.bsky.social PASSWORD=xxx FEED_HOSTNAME=your.domain ./scripts/publish.py --all 13""" 14 15import os 16import sys 17from atproto import Client 18 19# feed definitions 20FEEDS = { 21 "music-atmosphere": { 22 "display_name": "music atmosphere", 23 "description": "posts with music links | https://music-atmosphere-feed.plyr.fm", 24 }, 25 "music-following": { 26 "display_name": "music (following)", 27 "description": "music posts from people you follow | https://music-atmosphere-feed.plyr.fm", 28 }, 29} 30 31 32def publish_feed(client: Client, service_did: str, record_name: str, feed_info: dict): 33 response = client.com.atproto.repo.put_record( 34 { 35 "repo": client.me.did, 36 "collection": "app.bsky.feed.generator", 37 "rkey": record_name, 38 "record": { 39 "$type": "app.bsky.feed.generator", 40 "did": service_did, 41 "displayName": feed_info["display_name"], 42 "description": feed_info["description"], 43 "createdAt": client.get_current_time_iso(), 44 }, 45 } 46 ) 47 print(f"published: {response.uri}") 48 49 50def main(): 51 handle = os.environ["HANDLE"] 52 password = os.environ["PASSWORD"] 53 hostname = os.environ["FEED_HOSTNAME"] 54 55 client = Client() 56 client.login(handle, password) 57 58 service_did = f"did:web:{hostname}" 59 60 # determine which feeds to publish 61 if "--all" in sys.argv: 62 feeds_to_publish = list(FEEDS.keys()) 63 elif "--following" in sys.argv: 64 feeds_to_publish = ["music-following"] 65 else: 66 # default: just the main feed (backwards compatible) 67 record_name = os.environ.get("FEED_RECORD_NAME", "music-atmosphere") 68 display_name = os.environ.get("DISPLAY_NAME", "music atmosphere") 69 description = os.environ.get("FEED_DESCRIPTION", "posts with music links") 70 feeds_to_publish = [record_name] 71 FEEDS[record_name] = {"display_name": display_name, "description": description} 72 73 for record_name in feeds_to_publish: 74 feed_info = FEEDS[record_name] 75 publish_feed(client, service_did, record_name, feed_info) 76 77 78if __name__ == "__main__": 79 main()