Skip to content

Instantly share code, notes, and snippets.

@mnogu
Created October 17, 2023 09:47
Show Gist options
  • Save mnogu/c0a1a6d34182d040e6e2ee790d2e09cb to your computer and use it in GitHub Desktop.
Save mnogu/c0a1a6d34182d040e6e2ee790d2e09cb to your computer and use it in GitHub Desktop.
post with a mention
#
# $ python -m pip install chitose
# $ IDENTIFIER=xxx.bsky.social PASSWORD=aaaa-bbbb-cccc-dddd ACTOR=yyy.bsky.social python3 post.py
#
import json
import os
from datetime import datetime
from datetime import timezone
from chitose import BskyAgent
from chitose.app.bsky.feed.post import Post
from chitose.app.bsky.richtext.facet import ByteSlice
from chitose.app.bsky.richtext.facet import Facet
from chitose.app.bsky.richtext.facet import Mention
def main() -> None:
agent = BskyAgent(service='https://bsky.social')
agent.login(identifier=os.environ['IDENTIFIER'], password=os.environ['PASSWORD'])
actor = os.environ['ACTOR']
did = json.loads(agent.app.bsky.actor.get_profile(
actor=actor,
))['did']
feature = Mention(did=did)
mention = f'@{actor}'
byte_slice = ByteSlice(byte_start=0, byte_end=len(mention))
facet = Facet(index=byte_slice, features=[feature])
record = Post(text=f'{mention} test',
langs=['ja'],
facets=[facet],
created_at=datetime.now(timezone.utc).isoformat())
agent.post(record=record)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment