Created
September 29, 2010 10:27
-
-
Save swinton/602532 to your computer and use it in GitHub Desktop.
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
| #!/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