-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
publish_feed.py
executable file
·77 lines (58 loc) · 1.99 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
#!/usr/bin/env python3
# YOU MUST INSTALL ATPROTO SDK
# pip3 install atproto
from atproto import Client, models
# YOUR bluesky handle
# Ex: user.bsky.social
HANDLE: str = ''
# YOUR bluesky password, or preferably an App Password (found in your client settings)
# Ex: abcd-1234-efgh-5678
PASSWORD: str = ''
# The hostname of the server where feed server will be hosted
# Ex: feed.bsky.dev
HOSTNAME: str = ''
# A short name for the record that will show in urls
# Lowercase with no spaces.
# Ex: whats-hot
RECORD_NAME: str = ''
# A display name for your feed
# Ex: What's Hot
DISPLAY_NAME: str = ''
# (Optional) A description of your feed
# Ex: Top trending content from the whole network
DESCRIPTION: str = 'powered by The AT Protocol SDK for Python'
# (Optional) The path to an image to be used as your feed's avatar
# Ex: ./path/to/avatar.jpeg
AVATAR_PATH: str = ''
# (Optional). Only use this if you want a service did different from did:web
SERVICE_DID: str = ''
# -------------------------------------
# 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 "WHATS_ALF_URI" env var):', response.uri)
if __name__ == '__main__':
main()