Last active
September 5, 2017 00:41
-
-
Save angelworm/de95479b01dfd5613007b51e1c25f352 to your computer and use it in GitHub Desktop.
mastodonでのFAVを数える奴的な
This file contains hidden or 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 -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