Skip to content

Instantly share code, notes, and snippets.

@swinton
Created September 29, 2010 10:27
Show Gist options
  • Select an option

  • Save swinton/602532 to your computer and use it in GitHub Desktop.

Select an option

Save swinton/602532 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
A quick-and-dirty method for grabbing tweets from Twitter retrospectively, using the Search API.
Searches for mentions of "thisisengland" in this instance...
"""
import urllib
import anyjson
import sys
def main():
url = 'http://search.twitter.com/search.json'
q = '?q=thisisengland&page=1&rpp=100'
results = []
while q:
sys.stdout.write(str(q))
request = url + q
response = urllib.urlopen(request)
d = response.read()
response.close()
o = anyjson.deserialize(d)
sys.stdout.write(d)
if o.has_key('results'):
results.extend(o['results'])
q = o.get('next_page', None)
sys.stdout.flush()
# print results
return results
if __name__ == "__main__":
results = main()
output = open('thisisengland.json', 'w')
output.write(anyjson.serialize(results))
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment