Skip to content

Instantly share code, notes, and snippets.

@aiwas
Last active July 3, 2019 15:52
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 aiwas/5c77007c8e86c7b1cd1144895584e246 to your computer and use it in GitHub Desktop.
Save aiwas/5c77007c8e86c7b1cd1144895584e246 to your computer and use it in GitHub Desktop.
フォローしているアカウントの数 / フォローしているアカウントが所属するサーバーの数 を出すやつ
#!/usr/bin/env zsh
setopt NO_NOMATCH
list_url=()
list_tmp=()
res=0
page=1
while [ $res = 0 ]; do
list_tmp=$(curl -sS "https://${1}/users/${2}/following.json?page=${page}" | jq -r ".orderedItems[]")
if [ -n "$list_tmp" ]; then
for next_url in $(echo $list_tmp); do
list_url=($list_url $next_url)
done
((page++))
echo -n "page: $page\r"
else
res=1
fi
done
typeset -aU list_unique
for url in $list_url; do
url_tmp=$(echo $url | sed -E "s,https://([^/]+).*,\1,")
list_unique=($list_unique $url_tmp)
done
echo -n "\e[2K"; echo $(( (${#list_url} * 1.0) / (${#list_unique} * 1.0) ))
@aiwas
Copy link
Author

aiwas commented Jul 3, 2019

./bunsan.zsh <server> <account>

APIはAPのやつだけどエンドポイントはMastodonのやつで固定なので他で使えるかは不明

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment