Skip to content

Instantly share code, notes, and snippets.

@storborg
Created June 15, 2009 23:15
Show Gist options
  • Select an option

  • Save storborg/130419 to your computer and use it in GitHub Desktop.

Select an option

Save storborg/130419 to your computer and use it in GitHub Desktop.
"""
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