-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
publish_feed.py
executable file
·82 lines (61 loc) · 2.2 KB
/
publish_feed.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# YOU MUST INSTALL ATPROTO SDK
# pip3 install atproto
import os
from dotenv import load_dotenv
from atproto import Client, models
load_dotenv()
# YOUR bluesky handle
# Ex: user.bsky.social
HANDLE: str = os.environ.get('HANDLE')
# YOUR bluesky password, or preferably an App Password (found in your client settings)
# Ex: abcd-1234-efgh-5678
PASSWORD: str = os.environ.get('PASSWORD')
# The hostname of the server where feed server will be hosted
# Ex: feed.bsky.dev
HOSTNAME: str = os.environ.get('HOSTNAME')
# A short name for the record that will show in urls
# Lowercase with no spaces.
# Ex: whats-hot
RECORD_NAME: str = os.environ.get('RECORD_NAME')
# A display name for your feed
# Ex: What's Hot
DISPLAY_NAME: str = os.environ.get('DISPLAY_NAME')
# (Optional) A description of your feed
# Ex: Top trending content from the whole network
DESCRIPTION: str = os.environ.get('DESCRIPTION')
# (Optional) The path to an image to be used as your feed's avatar
# Ex: ./path/to/avatar.jpeg
AVATAR_PATH: str = os.environ.get('AVATAR_PATH')
# (Optional). Only use this if you want a service did different from did:web
SERVICE_DID: str = os.environ.get('SERVICE_DID')
# -------------------------------------
# NO NEED TO TOUCH ANYTHING BELOW HERE
# -------------------------------------
def main():
client = Client()
client.login(HANDLE, PASSWORD)
feed_did = SERVICE_DID
if not feed_did:
feed_did = f'did:web:{HOSTNAME}'
avatar_blob = None
if AVATAR_PATH:
with open(AVATAR_PATH, 'rb') as f:
avatar_data = f.read()
avatar_blob = client.upload_blob(avatar_data).blob
response = client.com.atproto.repo.put_record(models.ComAtprotoRepoPutRecord.Data(
repo=client.me.did,
collection=models.ids.AppBskyFeedGenerator,
rkey=RECORD_NAME,
record=models.AppBskyFeedGenerator.Record(
did=feed_did,
display_name=DISPLAY_NAME,
description=DESCRIPTION,
avatar=avatar_blob,
created_at=client.get_current_time_iso(),
)
))
print('Successfully published!')
print('Feed URI (put in "FEED_URI" env var):', response.uri)
if __name__ == '__main__':
main()