Skip to content

Commit

Permalink
Add Bluesky support
Browse files Browse the repository at this point in the history
  • Loading branch information
waldoj committed Nov 25, 2024
1 parent fccaa71 commit 75aa4a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# I Hope This Email Finds You

Posts to Mastodon completions to the sentence "I hope this email finds you." All content is sourced from Google Books, based on searches for phrases that satrt with "finds you."
Posts to Mastodon and Bluesky completions to the sentence "I hope this email finds you." All content is sourced from Google Books, based on searches for phrases that start with "finds you."

## Use

Enter your Google API key into `finds_you.py`, then plug various phrases into the script. It will populate `finds_you.txt` as it goes. Edit all the cruft out of the lines of text, remote duplicates, etc. Then enter your Mastodon server and API key into `post.sh`. Create a cron job that will run `post.sh` periodically. Congratulations, you have a goofy Mastodon bot.
Enter your Google API key into `finds_you.py`, then plug various phrases into the script. It will populate `finds_you.txt` as it goes. Edit all the cruft out of the lines of text, remote duplicates, etc. Then enter your Mastodon / Mastodon server and auth info into `post.sh`. Create a cron job that will run `post.sh` periodically. Congratulations, you have a goofy bot.
30 changes: 30 additions & 0 deletions post.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ MASTODON_SERVER="https://mastodon.social"
# Your Mastodon account's access token
MASTODON_TOKEN="TOKEN_HERE"

# URL of your Bluesky server, without a trailing slash
BLUESKY_SERVER="https://bsky.social"

# Your Bluesky account's username
BLUESKY_USERNAME="USERNAME_HERE"

# Your Bluesky account's password
BLUESKY_PASSWORD="PASSWORD_HERE"

# Define a failure function
function exit_error {
printf '%s\n' "$1" >&2
Expand Down Expand Up @@ -57,3 +66,24 @@ fi

# Log this to the post history
echo -n "$ENTRY" | md5sum | cut -d ' ' -f 1 >> post_history.txt

# Create an authentication session on Bluesky
ACCESS_JWT=$(curl -X POST $BLUESKY_SERVER/xrpc/com.atproto.server.createSession \
-H "Content-Type: application/json" \
-d '{"identifier": "'"$BLUESKY_USERNAME"'", "password": "'"$BLUESKY_PASSWORD"'"}' \
| jq -r '.accessJwt')
RESULT=$?
if [ "$RESULT" -ne 0 ]; then
exit_error "Could not authenticate to Bluesky"
fi

# Post the message to Bluesky
curl -X POST $BLUESKY_SERVER/xrpc/com.atproto.repo.createRecord \
-H "Authorization: Bearer $ACCESS_JWT" \
-H "Content-Type: application/json" \
-d "{\"repo\": \"$BLUESKY_USERNAME\", \"collection\": \"app.bsky.feed.post\", \"record\": {\"text\": \"$POST\", \"createdAt\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}}"

RESULT=$?
if [ "$RESULT" -ne 0 ]; then
exit_error "Posting message to Bluesky failed"
fi

0 comments on commit 75aa4a8

Please sign in to comment.