Created
January 8, 2012 05:58
-
-
Save beret/1577410 to your computer and use it in GitHub Desktop.
Rank the users you follow on Twitter by their Followcost (Bash)
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
# This _will_ break if you follow over 500 accounts since it only does single requests. | |
# Also, I know nothing about parsing JSON; consider yourself warned. | |
# PS: If you follow over 500 accounts you are insane. | |
# Cross-platform: Linux! BSD! OSX! Solaris! Anything but Windows PowerShell! | |
# Requires: pcregrep (you'll need to install 'pcre' if you're on OSX) | |
## Part 1: Brain Pain & JSON | |
# Fetches user info, dumps it in following-json.txt if you want an aneurysm. | |
# Prints who you follow in following.txt then puts line-separated Followcost reports in userFC-json.txt | |
================================================================ | |
curl -G 'https://api.twitter.com/1/friends/ids.json' -d 'screen_name=HEY_BABE_PUT_YOUR_USERNAME_HERE' | pcregrep -o "(?<=\[).+?(?=\])" | curl -G 'https://api.twitter.com/1/users/lookup.json' --data-urlencode user_id@- | tee following-json.txt | pcregrep -o --buffer-size 1m "(?<=\"screen_name\"\:\").+?(?=\")" | tee following.txt | sed -r 's/(.+)/url=http\:\/\/followcost.com\/\1.json/g' | curl -K- | sed -r 's/\}\{/\}\n\{/g' > userFC-json.txt | |
# Same thing, but you only get the Followcost JSON output. | |
================================================================ | |
curl -G 'https://api.twitter.com/1/friends/ids.json' -d 'screen_name=HEY_BABE_PUT_YOUR_USERNAME_HERE' | pcregrep -o "(?<=\[).+?(?=\])" | curl -G 'https://api.twitter.com/1/users/lookup.json' --data-urlencode user_id@- | pcregrep -o --buffer-size 1m "(?<=\"screen_name\"\:\").+?(?=\")" | sed -r 's/(.+)/url=http\:\/\/followcost.com\/\1.json/g' | curl -K- | sed -r 's/\}\{/\}\n\{/g' > userFC-json.txt | |
## Part 2: Sorting! | |
# Sort by recent FollowCost | |
sort -grt: +8 -9 userFC-json.txt | |
# Sort by all-time FollowCost | |
sort -grt: +1 -2 userFC-json.txt | |
# Sort by @reply index | |
sort -grt: +7 -8 userFC-json.txt | |
# Print only usernames from the line-separated JSON - 'suitable' for filtering sort output. | |
# Eventually, I'll write an awful kludge to cut the crap of 'fat-free' JSON & show just names and one number. | |
SortedOutput | pcregrep -o "(?<=\"username\"\:\").+?(?=\")" |
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
## Component Snippets | |
# Fetches who you follow, then resolves their UIDs, yielding a huge wad of JSON. | |
curl --get 'https://api.twitter.com/1/friends/ids.json' --data 'screen_name=HEY_BABE_PUT_YOUR_USERNAME_HERE' | pcregrep -o "(?<=\[).+?(?=\])" | curl --get 'https://api.twitter.com/1/users/lookup.json' --data-urlencode user_id@- > brainpain.txt | |
# Parse usernames out of the JSON blob. 1 per line. | |
pcregrep -o --buffer-size 1m "(?<=\"screen_name\"\:\").+?(?=\")" following-json.txt > following.txt | |
# Generate FC API URLs - the 'url=' part is needed because curl is a frustrating utility. (wget > curl) | |
sed -r 's/(.+)/url=http\:\/\/followcost.com\/\1.json/g' following.txt | curl -K- > userFC-json.txt | |
# Split FC JSON blob 1 user per line | |
sed -ri 's/\}\{/\}\n\{/g' userFC-json.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment