Top Banner
What's in a Tweet?
13

What's in a Tweet?

May 19, 2015

Download

Technology

rogueveda

A very basic presentation on using Python to access the Twitter API and search public stings for a text string.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: What's in a Tweet?

What's in a Tweet?

Page 2: 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.

Page 3: What's in a Tweet?

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.

Page 4: What's in a Tweet?

Variable Setup

Page 5: What's in a Tweet?

What Twitter Actually Returns to You

So you've set up user_timeline. And what is that exactly?

Output:

Page 6: What's in a Tweet?

Let's print user_timeline.

Just because we want to see what it looks like.

Page 7: What's in a Tweet?
Page 8: What's in a Tweet?

OMG What Was That

Page 9: What's in a Tweet?

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. 

Page 10: What's in a Tweet?

I found a JSON formatter to be useful.http://jsonformatter.curiousconcept.com/

Page 11: What's in a Tweet?

Basic Python Dictionary Methods:

Page 12: What's in a Tweet?

And Here's How the Goal is Achieved:

FOR loop:

With an IF loop:

And some output:

Page 13: What's in a Tweet?

Results!