Last active
February 11, 2024 23:21
-
-
Save mamemomonga/a1bf18fb05346c8ab54a84c6b7f2ab61 to your computer and use it in GitHub Desktop.
BlueSkyにシェルスクリプトで投稿する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
# BlueSkyにシェルスクリプトで投稿する | |
# 必要なもの bash, curl, jq | |
# カレントディレクトリに session.json, message.json が生成されます。 | |
# これらは秘匿情報が含まれている場合があります。ご注意ください。 | |
# しのさんさん(@shino3.bsky.social), syuiさん(@syui.ai) ありがとう! | |
BKY_ID="ユーザ名.bsky.social" | |
BKY_PASSWORD="パスワード" | |
BSY_MESSAGE="にゃにゃにゃ〜ん" | |
if [ ! -e 'session.json' ]; then | |
curl -v -X POST -H 'Content-Type: application/json; charset=utf-8' \ | |
-d '{"identifier":"'$BKY_ID'","password":"'$BKY_PASSWORD'"}' \ | |
https://bsky.social/xrpc/com.atproto.server.createSession > session.json | |
echo "" | |
fi | |
BSY_DID=$(cat session.json | jq -r .did) | |
BSY_AUTH=$(cat session.json | jq -r .accessJwt) | |
BSY_NOW=$(date '+%Y-%m-%dT%H:%M:%S.0000+09:00') | |
jq . > message.json << EOS | |
{ | |
"collection": "app.bsky.feed.post", | |
"repo": "$BSY_DID", | |
"record": { | |
"text": "$BSY_MESSAGE", | |
"createdAt": "$BSY_NOW", | |
"\$type": "app.bsky.feed.post" | |
} | |
} | |
EOS | |
echo "------------------------" | |
cat message.json | |
echo "------------------------" | |
curl -v -X POST \ | |
-H 'Content-Type: application/json; charset=utf-8' \ | |
-H 'Authorization: Bearer '$BSY_AUTH \ | |
-d @message.json \ | |
https://bsky.social/xrpc/com.atproto.repo.createRecord | jq . | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment