Created
June 2, 2012 19:56
-
-
Save ravikiranj/2859754 to your computer and use it in GitHub Desktop.
Get Tweets for a keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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