-
-
Save agusmakmun/c54736e8d92ced616466cf53e2093949 to your computer and use it in GitHub Desktop.
Mining twitter blog post (search_twitter.py)
This file contains hidden or 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, urllib2, json | |
def search_twitter(query, no_retweets=True): | |
if no_retweets: | |
# use the negation operator to filter out retweets | |
query += ' -RT' | |
url = 'http://search.twitter.com/search.json?%s' % urllib.urlencode({ | |
'q': query, | |
'lang': 'en', # restrict results to english tweets | |
'rpp': 100, # return 100 results per page (maximum value) | |
}) | |
response = json.loads(urllib2.urlopen(url).read()) | |
return response['results'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment