This is a template repository for using the 'blue-yonder' package. In order to create a repository with this template in your account or the account of your organization just click the 'Use this template' button on the top of this page and fill all the necessary information about ownership of the repository. The copy of this repo will appear in your account where you will be able to use and modify it the way you want.
The blue-yonder package is a pypi Python package that allows you to program your own automation of simple tasks on BlueSky network using Python. It can also be your door to the brave new world of AI, because it can serve as a connector between your Language Models and your social presence account on BlueSky if you know Python and can write programs that you need.
To install the blue-yonder package from pypi.org, run the following command in your terminal:
pip install blue-yonder To use the blue-yonder package, import it in your Python code:
from blue_yonder import Actor, Another, yonderNotice that the name of the library that you are using is blue_yonder, with an underscore.
There are more 'playful' aliases for the blue_yonder Client too; namely:
from blue_yonder import Butterfly, Flower, yonderThis is because Butterflies are the main 'clients' of the blue sky of course... and they interact with Flowers.
After using this template repository to create your own repository in your account, clone it to your computer and create a git excluded file .env using a .env_example format; use it to set the environment variables. As an alternative you can use git excluded config.yaml file formatted as it is shown in config_example.yaml file and go_configure function in a py file next to it.
The BlueSky service uses a handle, password as well as tokens associated with your account that let you make changes in the environment of the BlueSky. While authorized you can post text or images, change the preferences of your account and perform many other actions.
The best way to let your Python programs work with the BlueSky API is to use an .env file to store all the necessary credentials, which will be used automatically by the blue-yonder package in your log-in. As an alternative you can store them in a config.yaml file (and exclude it from git).
In browser all the necessary credentials obtained from BlueSky when you log-in are (automatically) stored in cookies of your browser, but if you are building your own automation you need to take care of that youself. This mechanism will help the Bluesky service to avoid overloads and will also save you 'limits' (there is a maximum number of authenticated API calls that you can make per minute and per day).
This is a most basic example of a plain text post that will be on your profile.
from blue_yonder import Actor
text = """This is a short post
(less than 300 characters)."""
my_actor = Actor()
result = my_actor.post(text)from blue_yonder import Actor
my_actor = Actor()
post = 'https://bsky.app/profile/multilogue.bsky.social/post/3lfngdvswe725'
reply_text = 'This is a reply'
reply = my_actor.in_reply_to(post).post(reply_text)This is an example of a plain text post quoting any other Bluesky post.
from blue_yonder import Actor
my_actor = Actor()
plain_text = 'This is an example of a plain text post quoting another post.'
url = 'https://bsky.app/profile/bsky.app/post/3l6oveex3ii2l'
result = my_actor.with_quoted_post(url).post(plain_text)You can add a quote of another Bluesky post to a reply.
from blue_yonder import Actor
my_actor = Actor()
post = 'https://bsky.app/profile/multilogue.bsky.social/post/3lfngdvswe725'
url = 'https://bsky.app/profile/bsky.app/post/3l6oveex3ii2l'
reply_text = 'This is a reply with a quote'
reply = my_actor.in_reply_to(post).with_quoted_post(url).post(reply_text)This is an example of a text (which can be an empty string) post with an embedded image (click the link above to see the full code of this example).
This is an example of a post with a link (actually a 'site card') to a page on any external site(click the link above to see the full code of this example).
There are several major inconveniences of short form text posts, which are:
- They are limited to 300 characters.
- The longer texts if formatted as a sequence of messages are hard to read. The solutions:
This is an example of simple automation that splits a given long text into 'postable' (less than 300 characters) parts and posts all of them as a thread.
from blue_yonder import Actor
from utilities import split_text
my_actor = Actor()
long_text = """The text of a long post
(more than 300 characters)...
...
end"""
posts = split_text(long_text)
result = my_actor.thread(posts_texts=posts)This is a most basic example of a plain text post that will be on your profile.
from blue_yonder import Actor
from utilities import create_text_images
plain_text = """This is a long text ...
end of that text."""
my_actor = Actor()
images = create_text_images(plain_text, output_dir=IMAGES_OF_TEXT_PATH)
my_actor.thread_of_images(paths_and_texts=images)This is a most basic example of a plain text post that will be on your profile.
from blue_yonder import Actor
from utilities import create_text_images
plain_text = """This is a long text ...
end of that text."""
my_actor = Actor()
url= 'https://bsky.app/profile/alxfed.bsky.social/post/3m4c2a2gaxs2r'
images = create_text_images(plain_text, output_dir=IMAGES_OF_TEXT_PATH)
my_actor.in_reply_to(url).thread_of_images(paths_and_texts=images)