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-magicpython-crontab
- 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, and a log file will be created in the ./logs/ directory. The log file will rotate when it reaches 10 MB, keeping up to 5 backup log files, each named with a timestamp for each execution.
Automating with Cron (Linux)#
The script will automatically set up a cron job to run every hour. If you need to manually verify it, run:
crontab -l
If you need to remove or modify the cron job, use:
crontab -e
Manually Set Up Cron Job#
If you wish to manually set up the cron job instead of relying on the script, follow these steps:
-
Open the crontab editor:
crontab -e -
Add the following line to run the script every hour at the top of the hour:
0 * * * * /path/to/your/.venv/bin/python3 /path/to/bluesky-avatar-updater/src/main.py
Replace /path/to/your/.venv/bin/python3 with the path to your virtual environment's Python interpreter and /path/to/bluesky-avatar-updater/src/main.py with the full path to the main.py script.
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.
-
Cron job not running? Verify that the cron job was properly set up using
crontab -lor set it up manually.
License#
This project is released under the MIT License. See the LICENSE file for full details.