Bluesky Avatar Updater#
Overview#
This repository contains a Python script designed to automatically update your Bluesky avatar based on the current hour. The script uses environment variables for configuration and reads a JSON file of blob CIDs to determine the appropriate avatar. This script was inspired by @dame.is's blog post 'How I made an automated dynamic avatar for my Bluesky profile'.
The script has been tested and is fully functional. It was developed on macOS but is intended for deployment on Linux.
Prerequisites#
Before running the script, ensure you have the following:
- Python 3.6 or later installed. If using Ubuntu, run
sudo apt update && sudo apt install -y python3 python3-pip python3-dev - The required Python packages (automatically installed if missing):
python-dotenvatprotorequestspython-magic
- A valid Bluesky account with the necessary API credentials.
Installation#
-
Clone the repository:
git clone https://github.com/ewanc26/bluesky-avatar-updater.git cd bluesky-avatar-updater -
Ensure the required package is installed (if necessary):
Before creating the virtual environment, make sure that the
python3-venvpackage is installed (this is necessary on Debian/Ubuntu systems to create virtual environments).sudo apt install python3.10-venv # Adjust the version if necessary (e.g., python3.9-venv) -
Create a virtual environment and install dependencies:
Now, create a new virtual environment and activate it. This isolates the package dependencies for your project.
python3 -m venv .venv source .venv/bin/activate # On Windows use: .venv\Scripts\activate -
Install dependencies within the virtual environment:
With the virtual environment activated, install the required packages listed in the
requirements.txtfile:pip install -r requirements.txt -
Configure environment variables:
-
Place your
.envfile in the../assetsdirectory relative to the script. -
The
.envfile should contain the following entries:ENDPOINT=your_endpoint HANDLE=your_handle PASSWORD=your_password (app passwords are recommended) DID=your_did
-
-
Prepare the JSON file:
-
Ensure that a
cids.jsonfile is located in the../assetsdirectory. This file should map each hour (in two-digit format) to a corresponding blob CID. Example:{ "00": "cid_for_midnight", "01": "cid_for_1am", "02": "cid_for_2am" }
-
Usage#
To run the script, execute:
python -u ./src/main.py
The script will:
- Load the environment configuration from
../assets/.env. - Read the blob CIDs from
../assets/cids.json. - Determine the current hour and select the appropriate blob CID.
- Authenticate using the AT Protocol.
- Update the Bluesky avatar accordingly.
Execution logs will be displayed directly in the console.
Automating with Cron (Linux)#
To run the script automatically every hour, a cron job is set up within the script. If you need to manually verify it, run:
crontab -l
If you need to remove or modify the cron job, use:
crontab -e
Troubleshooting#
-
Environment variables not loading? Ensure the
.envfile is correctly placed in../assets/. -
Script exits with missing dependencies? The script will attempt to install missing packages, but you can manually install them using:
pip install -r requirements.txt -
Endpoint not responding? Verify that the Bluesky API endpoint is correct and accessible.
License#
This project is released under the MIT License. See the LICENSE file for full details.