this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feature: added script and documentation for publishing feed records

Signed-off-by: Nick Gerakines <12125+ngerakines@users.noreply.github.com>

+69
+1
.gitignore
··· 21 21 # release hooks 22 22 create-release-*.sh 23 23 .tmp.release_info 24 + venv/
+28
docs/publish-feed.md
··· 1 + # How to publish a feed 2 + 3 + Supercell is a feed generator, that is to say it is the service that fulfills feed requests and returns the posts that are displayed. 4 + 5 + To invoke Supercell, you first need to create a record on your PDS saying that you are publishing a feed for others to use. This is called feed publishing. 6 + 7 + This is done by creating a record on your PDS with the following structure: 8 + 9 + ```json 10 + { 11 + "$type": "app.bsky.feed.generator", 12 + "did": "did:web:the_hostname", 13 + "display_name": "Feed A", 14 + "description": "A useful feed.", 15 + "created_at": "2024-10-30T16:15:31Z" 16 + } 17 + ``` 18 + 19 + The `did` is a did:web identifier where the hostname is used to service a DID document that contains a "BskyFeedGenerator" service structure with the hostname to make API calls. 20 + 21 + ## Publish script 22 + 23 + The `publish.py` script can be used to create new feed records or update existing ones. 24 + 25 + 1. Create a new virtual environment to run the script in: `python -m venv ./venv/` 26 + 2. Install the atproto library in the virtual environment: `./venv/bin/pip install atproto` 27 + 3. Invoke the script using the virtual environment: `./venv/bin/python ./etc/publish.py --help` 28 +
+40
etc/publish.py
··· 1 + #!/usr/bin/env python3 2 + from typing import Optional 3 + from atproto import Client, models 4 + import argparse 5 + 6 + def main(user: str, password: str, name: str, description: str, server: str, rkey: Optional[str] = None, image: Optional[str] = None): 7 + client = Client() 8 + client.login(user, password) 9 + avatar_blob = None 10 + if image: 11 + with open(image, 'rb') as f: 12 + avatar_data = f.read() 13 + avatar_blob = client.upload_blob(avatar_data).blob 14 + response = client.com.atproto.repo.put_record(models.ComAtprotoRepoPutRecord.Data( 15 + repo=client.me.did, 16 + collection=models.ids.AppBskyFeedGenerator, 17 + rkey=rkey, 18 + record=models.AppBskyFeedGenerator.Record( 19 + did=f'did:web:{server}', 20 + display_name=name, 21 + description=description, 22 + avatar=avatar_blob, 23 + created_at=client.get_current_time_iso(), 24 + ) 25 + )) 26 + print('Feed URI :', response.uri) 27 + 28 + 29 + if __name__ == '__main__': 30 + parser = argparse.ArgumentParser() 31 + parser.add_argument("-u", "--user", help="The handle to publish the feed under. Ex: smokesignal.events") 32 + parser.add_argument("-p", "--password", help="The password for the handle publishing the feed") 33 + parser.add_argument("-n", "--name", help="The name of the feed. Ex: What's Hot") 34 + parser.add_argument("-d", "--description", help="The description of the feed. Ex: Top trending content from the whole network") 35 + parser.add_argument("-i", "--image", default=None, help="The path to the avatar image for the feed. Ex: ./path/to/avatar.jpeg") 36 + parser.add_argument("-s", "--server", help="The server hostname servicing the feed. Ex: feeds.smokesignal.events") 37 + parser.add_argument("-r", "--rkey", default=None, help="The rkey of a feed being updated.") 38 + args = parser.parse_args() 39 + main(args.user, args.password, args.name, args.description, args.server, args.rkey, args.image) 40 +