summary refs log tree commit diff
path: root/www/photo.causal.agency/mastodon.sh
diff options
context:
space:
mode:
Diffstat (limited to 'www/photo.causal.agency/mastodon.sh')
-rw-r--r--www/photo.causal.agency/mastodon.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/www/photo.causal.agency/mastodon.sh b/www/photo.causal.agency/mastodon.sh
new file mode 100644
index 00000000..1eaa1114
--- /dev/null
+++ b/www/photo.causal.agency/mastodon.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+set -eu
+
+Instance=https://tilde.zone
+Root=${1:-static}
+
+if ! test -f app.json; then
+	echo 'No app.json!' >&2
+	exit 1
+fi
+chmod 600 app.json
+
+if ! test -f token.json; then
+	client_id=$(jq -r .client_id app.json)
+	client_secret=$(jq -r .client_secret app.json)
+	echo "Please open ${Instance}/oauth/authorize?client_id=${client_id}&scope=write&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code"
+	printf 'Enter code: '
+	read -r code
+	curl -Ss -X POST \
+		-F 'grant_type=authorization_code' \
+		-F "client_id=${client_id}" \
+		-F "client_secret=${client_secret}" \
+		-F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \
+		-F "code=${code}" \
+		${Instance}/oauth/token >token.json
+fi
+chmod 600 token.json
+
+access_token=$(jq -r .access_token token.json)
+
+if ! test -f posted.txt; then
+	touch posted.txt
+fi
+
+photo=$(
+	find ${Root} -type f -path '*/0*/*.jpg' |
+	sort | comm -13 posted.txt - | head -n 1
+)
+preview=${Root}/preview/${photo##*/}
+
+media_id=$(
+	curl -Ss -X POST \
+		-H "Authorization: Bearer ${access_token}" \
+		-F "file=@${preview}" \
+		${Instance}/api/v2/media |
+	jq -r .id
+)
+
+curl -Ss -X POST \
+	-H "Authorization: Bearer ${access_token}" \
+	-F "media_ids[]=${media_id}" \
+	${Instance}/api/v1/statuses >/dev/null
+
+echo ${photo} >>posted.txt
e='2020-03-03 02:01:41 -0500'>2020-03-03Remove setoptJune McEnroe 2020-03-03Use getopts in shell scriptsJune McEnroe 2020-02-27Style %T outside of Rs in italicJune McEnroe 2020-02-26Add Fierce Femmes and Notorious LiarsJune McEnroe 2020-02-23Add This Is How You Lose the Time WarJune McEnroe 2020-02-22Add See Ya LaterJune McEnroe 2020-02-20Remove wiki scriptJune McEnroe 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe 2020-01-28Change scout sensitivity to 1.4June McEnroe 2020-01-28Import shows.txtJune McEnroe