Unfollow all twitter users not following back to you


/ Published in: Bash
Save to your folder(s)

Also posted at http://pastebin.com/9FzakUcd


Copy this code and paste it in your HTML
  1. #! /usr/bin/env bash
  2. # unfollow_nofriends.sh
  3. # unfollow twitter users not following back to you.
  4. # ksaver (at identi.ca), Aug, 2010.
  5. # uses friendorfollow.com csv file at:
  6. # "http://friendorfollow.com/$USERNAME/results/?\
  7. # orderby=undefined&type=following&format=csv"
  8. # and twitter API at:
  9. # "http://api.twitter.com/1/friendships/destroy/$ID.xml"
  10. # Requieres: curl, egrep, in order to work properly.
  11. # This script has been written to help in some twitter account maintanance,
  12. # please do not use it for evil pourposes :-)
  13. # Public Domain Code.
  14. # Not warranty at all.
  15.  
  16. # Edit this two lines according to your correct twitter account:
  17. USERNAME='username123'
  18. PASSWORD='password321'
  19.  
  20. TWIT_AUTH="$USERNAME:$PASSWORD"
  21. TWIT_API="http://api.twitter.com/1/friendships/destroy"
  22. FOF_CSV="http://friendorfollow.com/$USERNAME/results/?orderby=undefined&type=following&format=csv"
  23. ERR=0
  24. OK=0
  25.  
  26. function _curl()
  27. {
  28. /usr/bin/env curl -s -A 'Mozilla' "$@"
  29. }
  30.  
  31. function get_nofriend_list()
  32. {
  33. _curl "$FOF_CSV" |cut -d',' -f2 |egrep -e [0-9]
  34. }
  35.  
  36. function unfollow_id()
  37. {
  38. ID="$1"
  39. _curl -u "$TWIT_AUTH" -d '' "$TWIT_API/$ID.xml" \
  40. |grep '<error>' > /dev/null && return 1 || return 0
  41. }
  42.  
  43. function error_msg()
  44. {
  45. ID="$1"
  46. echo "Error unfollowing user with ID: $ID"
  47. }
  48.  
  49. function __main__()
  50. {
  51. ## Getting no-friend list in an Array...
  52. NOFRIENDS=( $(get_nofriend_list) )
  53.  
  54. echo "Unfollowing ${#NOFRIENDS[@]} total users..."
  55. for id in ${NOFRIENDS[@]}
  56. do
  57. unfollow_id $id && let OK=$OK+1 || (error_msg $id && let ERR=$ERR+1)
  58. done
  59.  
  60. echo "$OK total no-friend users unfollowed and $ERR errors."
  61. }
  62.  
  63. ## Run script if not called by source.
  64. if [ "$0" != 'bash' ]
  65. then
  66. __main__
  67. fi

URL: http://identi.ca/ksaver

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.