What's in a Tweet?
May 19, 2015
What's in a Tweet?
The Goal:
Search the most recent public tweets of any user for a specific text string. Using myself as an example, let's search for the string 'FCPX', as I'm a video editor and tweeted a lot about that recently.
Finding a Python wrapper for the Twitter API
Twython is pretty cool. It's as easy as this:
Start up Terminal and type easy_install twython.
Done.
Variable Setup
What Twitter Actually Returns to You
So you've set up user_timeline. And what is that exactly?
Output:
Let's print user_timeline.
Just because we want to see what it looks like.
OMG What Was That
No, it's not wrong.
It's JSON data. Every tweet has much more information associated with it than just the raw text you see online. It looks intimidating, but it's not. JSON is just a bunch of nested dictionaries. You can easily parse JSON with basic Python dictionary methods.
I found a JSON formatter to be useful.http://jsonformatter.curiousconcept.com/
Basic Python Dictionary Methods:
And Here's How the Goal is Achieved:
FOR loop:
With an IF loop:
And some output:
Results!