Twitter hashtag frequency by Python


Spent some time this evening trying to figure out the new  (1.1) Twitter API.  The new API demands authentication, and it took me a while before I managed to figure out – thanks to Google! 🙂 – how to do that.  I didn’t find any obvious way to do that directly from Python, so I had to create a php-script running on my webserver for extracting the wanted data from Twitter.   If anyone knows how to access the 1.1 Twitter API, including authentication, directly from Python, let me know, I’d prefer not to mess with php…

Then, Python again demoes its power – I really start to like the language! –  it was very quick to learn how to parse the json-structure returned by the php-script.

With a bit of list and dictionary manipulation in Python, some 50+ lines of Python code, I was able to produce a file for Gephi to do a layout on the most frequent Twitter hashtags, as tweeted by my followers, over the past few days or so (more correctly, the last 200 tweets for each follower).  In fact, the program does quite a bit more, e.g. matching tweeters, but I’ll leave the display part of that for later…

The only major surprise in the resulting graph was “betting“…! I never bet on anything, I don’t know anyone who does, still the tag ranks quite high… Apparently there are betting men (or women),  within 1 degree from me… Scary! 🙂

[Edit] Couldn’t resist doing the same exercise for those that I follow, and below is the graph:



About swdevperestroika

High tech industry veteran, avid hacker reluctantly transformed to mgmt consultant.
This entry was posted in development and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s