I’ve used a lot of twitter clients over the years, I even wrote one back in ’08. TweetDeck is pretty good, but Air is shoddy on 64-bit Linux, and so it didn’t integrate well and would crash.
I rejected Gwibber and Choqok, just not my style. My old web standby Brizzly seems pretty lame these days too. Then I found Hotot. It’s awesome. It’s like a Linux native TweetDeck, but with a friendlier, more welcoming feel.
If you are looking for a Linux twitter client, you have got to give Hotot a try.
So, about a week or go I dove back into Ruby out of necessity. The Twitter daemon I had written in Python for Confurrent was chronically ill. My socket would block and eat 100% CPU and it seemed like nobody knew how to work around it, least of all me.
So I pulled out Ruby. I’ve only ever done any real Ruby work with Rails, when I wrote ThirtyDayList to learn the tech.
One thing I will note is that learning Rails basics does not teach you Ruby, or at least not enough Ruby to be useful. However, writing my Twitter daemon has made me confident in Ruby, and I like it a lot more now than after the Rails experiment.
The daemon was quick to write, using Tweetstream, and I only ran into one roadblock, which was all my fault.
See, I wanted to use the track method, which takes an unlimited and variable set of arguments (like *args in Python) but I had my arguments in an array. I could not figure out how to pass those on correctly, and even bust into the gem and started adding code to get it to work.
I finally realized that there is no way that there isn’t a built-in for this and I went back to Googling. A short while later I found a short post from detailing exactly what I should be doing.
Evidently you can use the asterisk to unpack an array for this. Super easy, but I feel silly for not finding that sooner. The pitfalls of unfocused autodidactism.
The Wrong Way
predicates = [ 'a', 'b', 'c' ]
@client.track( predicates )
# Tracks 'abc'
The Right Way
predicates = [ 'a', 'b', 'c' ]
@client.track( *predicates )
# Tracks 'a,b,c'
I’ve been meaning to check out the Tweepy for a while and got around to it today. It’s a Python library for interacting with Twitter. The feature I’m most interested in is the streaming API support, which isn’t advertised much by Tweepy but seems pretty solid.
Tweepy has pretty good documentation, and the code is terse and readable, but what I found most useful was the examples repository, which had the only example of streaming with Tweepy that I could find in the official documentation.
It’s really straightforward. Implement a tweepy.streaming.StreamListener to consume data, set up a tweepy.streaming.Stream with that listener, then pull the trigger on the streaming function you want to use.
Here’s a quick example I set up to track the filter keyword “omaha”.
# -*- coding: utf-8 -*-
from tweepy.streaming import StreamListener, Stream
class Listener ( StreamListener ):
def on_status( self, status ):
print '-' * 20
if __name__ == "__main__":
USERNAME = "YourUsernameHere"
PASSWORD = "YourPasswordHere"
listener = Listener()
stream = Stream(
stream.filter( track=( "omaha", ) )