Skip to content

Instantly share code, notes, and snippets.

@agusmakmun
Forked from kwellman/search_twitter.py
Created June 1, 2016 21:37
Show Gist options
  • Save agusmakmun/c54736e8d92ced616466cf53e2093949 to your computer and use it in GitHub Desktop.
Save agusmakmun/c54736e8d92ced616466cf53e2093949 to your computer and use it in GitHub Desktop.
Mining twitter blog post (search_twitter.py)
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