Created
June 15, 2009 23:15
-
-
Save storborg/130419 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
| """ | |
| walk through related tags on twitter. | |
| start it with something like python twitterwalk.py sxsw | |
| """ | |
| import sys, re | |
| from twitter import Twitter | |
| if len(sys.argv) > 1: | |
| initial_tag = sys.argv[1] | |
| else: | |
| initial_tag = 'python' | |
| t = Twitter(domain='search.twitter.com') | |
| tags = ['#' + initial_tag] | |
| seen_tags = set() | |
| for tag in tags: | |
| if not tag in seen_tags: | |
| print "%d %s %d" % (len(seen_tags), tag, len(tags)) | |
| seen_tags.add(tag) | |
| new_tags = set() | |
| for msg in (tweet['text'] for tweet in t.search(q=tag)['results']): | |
| new_tags.update(set([m.lower() for m in re.findall('#\w+', msg)])) | |
| print " " + ' '.join(new_tags) | |
| tags += list(new_tags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment