PhotosToSocial is a python script to publish post with photos into social media (WordPress and BluSky by now). The goal is to be able to post at least a photo every day without effort.
The workflow is like this:
- Export the photos from lightroom or your favourite program into
PHOTOS_TO_SOCIAL_HOMEdirectory. Remove all metadata you don't want to expose before loading the photos into PhotosToSocial, I personally use the great Jeffrey Friedl's Metadata Wrangler Export Filter. - Load (running
main.py --load) loads photos from home directory and prepare posts.PhotoLoaderwill load new photos and read metadata. This process will load new photos, comparing with posts already loaded and stored intoPOSTS_FILENAMEjson file.PostBuildercreates post from photos- Metadata:
Titlewill be added to the post text. If multiple photos in the same job share the sametitle, then it will merge in a single post with all photos.Captionwill be added to the post text. If multiple photos are grouped in the same post, thecaptionfield will be used for the post text, appending the caption of every photo to the post's text, and asalttext of the image (if it has content).Keywordsstarting with#will be added to the post. If multiple photos are grouped in the same post, duplicated keywords are ignored.
- The posts are stored into
POSTS_FILENAMEjson file.
- Metadata:
- Post (running
main.py --post) sends next post to Social media. This option is intended to be called by a daily cron job.- Reads next post to be published from
POSTS_FILENAMEjson file. - Send the post to social media, currently to BlueSky and WordPress (using Post by Email feature).
- Updates the post at
POSTS_FILENAMEjson file.
- Reads next post to be published from
Set these environment variables to set up the script:
PHOTOS_TO_SOCIAL_HOME: Home directory were photos andPOSTS_FILENAMEjson file are stored.BLUE_SKY_USERNAME: Your BlueSky username.BLUE_SKY_PASSWORD: Your BlueSky password.GMAIL_USER_EMAIL: Your gmail email.GMAIL_APP_PASSWORD: An gmail app password.WORD_PRESS_POST_BY_EMAIL_TO: the recipient address configured for WordPress Post by Email.
- Create the virtual environment:
python -m venv .venv - Activate the virtual environment:
source .venv/bin/activate - Install dependencies:
pip3 install -r requirements.txt
PhotosToSocial uses ExifTool to read tags from photos. Follow the instructions on ExifTool installation page.
- Set the environment variables in
/etc/environmentfile so are available for cron. - Use update.sh to update the project.
- Use load.sh and send.sh for easily set up the scheduled tasks. Set as executable scripts:
chmod +x PhotosToSocial/update.sh chmod +x PhotosToSocial/load.sh chmod +x PhotosToSocial/send.sh
- Run
crontab -eto set up the cron expressions, for instance:# Update every day at 6:00 0 6 * * * $HOME/PhotosToSocial/update.sh › $HOME/social/last_cron_update.log 2>&1 # Load new photos every day at 6:30 30 6 * * * $HOME/PhotosToSocial/load.sh > $HOME/social/last_cron_load.log 2>&1 # Post every day at 7:00 0 7 * * * $HOME/PhotosToSocial/send.sh › $HOME/social/last_cron_send.log 2>&1