Last active
February 23, 2021 06:38
-
-
Save hata6502/f527fbfb9756b91c9acbf4d8cf94d83c to your computer and use it in GitHub Desktop.
This file contains 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/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