Skip to content

Instantly share code, notes, and snippets.

@unascribed
Last active August 14, 2019 21:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unascribed/98884acf9eceff8e3fa901fe6e8194ef to your computer and use it in GitHub Desktop.
Save unascribed/98884acf9eceff8e3fa901fe6e8194ef to your computer and use it in GitHub Desktop.
#!/bin/bash
token='ACCESS_TOKEN_HERE (needs write.statuses and write.media scopes)'
instance='sleeping.town'
tmp=`mktemp voidXXXXXX.json`
read -ep 'Content warning? ' cw
read -ep 'Attachment? ' attachment
if [ -n "$attachment" ]; then
read -ep 'Attachment alt text? ' alt_text
echo "Uploading attachment..."
attachment=`curl -s -X POST -H "Authorization: Bearer $token" -F "file=@$attachment;filename=$(date '+%s')" -F "description=$alt_text" https://$instance/api/v1/media`
attachment_id=`echo $attachment | jq '.id'`
fi
echo 'Write your post. ^D to finish, ^C to cancel'
jq --slurp -Rr 'rtrimstr("\n")|{status: "\(.) 🌌",spoiler_text:"'"$cw"'",visibility:"unlisted",media_ids:['$attachment_id']}' > $tmp
curl -s -X POST -H "Authorization: Bearer $token" -H 'Content-Type: application/json' --data "@$tmp" https://$instance/api/v1/statuses >/dev/null
rm $tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment