Skip to content

Instantly share code, notes, and snippets.

@kwellman
Created May 5, 2012 21:13
Show Gist options
  • Save kwellman/2605617 to your computer and use it in GitHub Desktop.
Save kwellman/2605617 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