Skip to content

Instantly share code, notes, and snippets.

@hata6502
Last active February 23, 2021 06:38
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 hata6502/f527fbfb9756b91c9acbf4d8cf94d83c to your computer and use it in GitHub Desktop.
Save hata6502/f527fbfb9756b91c9acbf4d8cf94d83c to your computer and use it in GitHub Desktop.
#!/bin/env bash
if [[ $# == 0 ]]; then
echo "Usage: ./twitter-actual-follower.sh (screen_name)" >&2
echo "twurl is required. " >&2
exit 1
fi
echo "Fetching data... (It may take some time. )" >&2
cursor="-1"
friendsCounts=""
while :; do
followersList="$(twurl "/1.1/followers/list.json?count=200&cursor=$cursor&include_user_entities=false&screen_name=$1")"
# For rate limit
sleep 60
if [[ $(echo "$followersList" | jq ".errors | length") != 0 ]]; then
echo "$followersList" >&2
exit 1
fi
friendsCounts="$friendsCounts$(echo "$followersList" | jq ".users[].friends_count")
"
cursor="$(echo "$followersList" | jq -r ".next_cursor_str")"
if [[ "$cursor" == "0" ]]; then
break
fi
done
# Remove new-line at the end
friendsCounts=$(echo "$friendsCounts" | head -c -1)
echo "$friendsCounts" | awk '{actualFollower += 1/$1} END {print actualFollower}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment