Skip to content

Instantly share code, notes, and snippets.

@ravikiranj
Created June 2, 2012 19:56
Show Gist options
  • Save ravikiranj/2859754 to your computer and use it in GitHub Desktop.
Save ravikiranj/2859754 to your computer and use it in GitHub Desktop.
Get Tweets for a keyword
import urllib
import urllib2
import json
#start getTwitterData
def getData(keyword):
url = 'http://search.twitter.com/search.json'
data = {'q': keyword, 'lang': 'en', 'result_type': 'recent'}
params = urllib.urlencode(data)
try:
req = urllib2.Request(url, params)
response = urllib2.urlopen(req)
jsonData = json.load(response)
tweets = []
for item in jsonData['results']:
tweets.append(item['text'])
return tweets
except urllib2.URLError, e:
self.handleError(e)
return tweets
#end
tweets = getData("messi");
print tweets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment