Last active
May 20, 2017 21:30
-
-
Save drench/f068ac13816bca51369e3fcb1d1b4177 to your computer and use it in GitHub Desktop.
A shell script to fetch your twitter followers and followings. Requires https://github.com/twitter/twurl and https://github.com/stedolan/jq
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/sh | |
case "$1" in | |
followers) | |
api_endpoint="/1.1/followers/list.json" | |
output_prefix="followers" | |
;; | |
following) | |
api_endpoint="/1.1/friends/list.json" | |
output_prefix="following" | |
;; | |
*) | |
echo "Specify either 'followers' or 'following'" | |
exit 111 | |
;; | |
esac | |
cursor=-1 | |
n=0 | |
while true; do | |
outfile="${output_prefix}-${n}.json" | |
url="${api_endpoint}?skip_status=true&count=200&cursor=${cursor}" | |
echo "calling $url and sending output to $outfile" | |
twurl $url > $outfile | |
error_code=$(jq '.errors[0].code' < $outfile) | |
if [ "$error_code" == "88" ]; then | |
echo "Rate limited. Let's wait a minute." | |
sleep 60 | |
rm $outfile | |
continue | |
else | |
cursor=$(jq '.next_cursor' < $outfile) | |
fi | |
if [ $cursor == "0" ]; then | |
echo "done" | |
break | |
fi | |
sleep 2 | |
((n++)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To combine the JSON files and sort the result by twitter user id: