Here's what I came up with. It does the following:
- Builds the HTTP Basic Auth header
- Fetches all your followers (100 at a time until no more are found)
- Fetches all your friends (again, 100 at a time)
- Looks for each of your followers in your friends list
- Prints each follower that you haven't marked as a friend
- Adds commons (friends who follow you back) to a list
- Prints each friend that's not following you
- Prints the list of commons
#!/usr/bin/newlisp
# Build an HTTP Basic Auth header for get-url.
# Set 'user and 'pass manually
(set 'user "YourTwitterName" 'pass "NotMyPasswd")
(set 'hedr (append "Authorization: Basic "
(base64-enc (append user ":" pass)) "\r\n\r\n"))
# Grabs followers until results list has less than 100
(set 'page 0) (do-until (< numthese 100) (inc page)
(set 'xml (get-url (append
"http://twitter.com/statuses/followers.xml?page="(string page))
5000 hedr))
(set 'these (find-all "<screen_name>(.*)</screen_name>" xml $1))
(cond ((= page 1) (set 'fol these))
((> page 1) (set 'fol (append fol these))))
(set 'numthese (length these))
)
# Grabs friends until results list has less than 100
(set 'page 0) (do-until (< numthese 100) (inc page)
(set 'xml (get-url (append
"http://twitter.com/statuses/friends.xml?page="(string page))
5000 hedr))
(set 'these (find-all "<screen_name>(.*)</screen_name>" xml $1))
(cond ((= page 1) (set 'fri these))
((> page 1) (set 'fri (append fri these))))
(set 'numthese (length these)))
# Iterate followers against friends list
(dolist (follower fol)
(if (nil? (find follower fri))
(print (append follower " is not a friend\r\n"))
# If follower and friend, push to com list
(if (nil? com) (set 'com (list follower))
(push follower com))))
# Iterate friends against followers list
(dolist (friend fri)
(if (nil? (find friend fol))
(print (append friend " is not following\r\n")) (inc notfol)))
# Print list of common (friend & follow)
(dolist (common com)
(print (append common " is following back.\r\n")))
(exit)
Why'd I do this? Why not use Twitter Karma or some other online tool?
- I didn't want to enter my username and password into someone else's web app.
- I wanted a quick programming project that could take up part of my weekend.
- It was fun.