Skip to content

Instantly share code, notes, and snippets.

@angelworm
Last active September 5, 2017 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelworm/de95479b01dfd5613007b51e1c25f352 to your computer and use it in GitHub Desktop.
Save angelworm/de95479b01dfd5613007b51e1c25f352 to your computer and use it in GitHub Desktop.
mastodonでのFAVを数える奴的な
#!/bin/bash -ue
# すごーいを取ってくるやつ。
# $ACCESS_TOKENはweb clientのstreamingのパラメーターにあるものを使うと楽。
# useage:
# $ ./favs.sh $ACCESS_TOKEN
ACCESS_TOKEN=${1:?./favs.sh ACCESS_TOKEN [max_id]}
MASTODON='https://mstdn.kemono-friends.info'
HEADERS=$(mktemp)
RESPONSE=$(mktemp)
OUT=favs.json
MAX_ID=${2:-''}
SUM=0;
if [[ -e ${2:-''} ]]; then
rm -f $OUT;
fi;
while true;
do
curl --header "Authorization: Bearer $ACCESS_TOKEN" \
-sS \
--dump-header $HEADERS \
--retry 5 \
"${MASTODON}/api/v1/favourites?limit=40&max_id=${MAX_ID}" \
> $RESPONSE
RESP=$(cat $RESPONSE | jq '. | length')
FIRST_DATE=$(cat $RESPONSE | jq '.[0].created_at')
(( SUM += RESP ));
MAX_ID=$(cat $HEADERS | grep Link | grep -oE 'max_id=[0-9]+' | cut -d '=' -f 2)
cat $RESPONSE >> $OUT
if [ -z "$MAX_ID" ]; then
echo "found: $SUM"
exit;
fi;
echo "next: $MAX_ID, from: $FIRST_DATE, sum: $SUM"
sleep 7;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment