Banter – view twitter conversations
We all follow a few celebrities on Twitter. Sometimes it is fun to see their conversations, but then you have to follow the @ replies back and forth between Twitter pages and that can get out of hand fairly quickly.
Now to combat this horrible problem I whipped up this script to use the Twitter search API to grab the last bunch of @ replies between two users.
Use it like:
$ python banter.py nathanfillion simonpegg
import urllib2 import simplejson def tweet_date_cmp(a, b): if a['id'] > b['id']: return 1 elif a['id'] == b['id']: return 0 else: #a['id'] < b['id']: return -1 def get_thread(user_a, user_b): url_t = "http://search.twitter.com/search.json?from=%s&to=%s" to_a = simplejson.loads( urllib2.urlopen(url_t % (user_b, user_a)).read()) to_b = simplejson.loads( urllib2.urlopen(url_t % (user_a, user_b)).read()) thread = [] thread.extend(to_a['results']) thread.extend(to_b['results']) return sorted(thread, tweet_date_cmp) if __name__ == '__main__': import sys thread = get_thread(sys.argv[1], sys.argv[2]) for item in thread: print "%s: %s" % (item['from_user'], item['text'])
I might code this up into a simple web app to make it more accessible.
Have fun, and don’t stalk too many people.
-Casey
