Tuesday, July 1, 2014

Collecting Tweeter Data using Python: Getting Started


NPL, Natural Language Processing, Test Mining are some of the hot topics for research for these day. With this article I'm going to introduce how to collect tweeter data using simple code in Python.

As the first step you  can install Python to your machine

  1. Install Python [Click Here] personally commanded 2.7 or upper
  2. Get Api Key [Sign in twitter]
  3. Install tweepy [Download tweepy from here ]

After all those steps you can download data from Tweeter. Here is the code for

import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener

ckey = '** your consumer_key **'
csecret = '** consumer secret **'
atoken = '** access token **'
asecret = '** access secret **'

class listner(StreamListener):

def on_data(self,data):
print data
return True

def on_error(self, status):
print status

auth = tweepy.OAuthHandler(ckey,csecret)
auth.set_access_token(atoken,asecret)

twitterStream = Stream(auth,listner())
twitterStream.filter(track=['car'])

when you run this code in the python shell twitter data about "car" will display on your shell

No comments:

Post a Comment

දෙහි

  දෙනකොට දෙහි මදි නොකියන්නම ඇබුලටම... මිරිකලා හොදටම හදනවා බීම පැණි බේරෙන්නම මදි නොකියන්න Photo by Yethu Mtshali on Unsplash