Skip to content

Instantly share code, notes, and snippets.

@neilkod
Created December 16, 2010 17:13
Show Gist options
  • Save neilkod/743672 to your computer and use it in GitHub Desktop.
Save neilkod/743672 to your computer and use it in GitHub Desktop.
def get_retweets(hashtag):
db = create_connection()
tweets = db.conftweets
regexp = re.compile(hashtag, re.IGNORECASE)
grpd = tweets.group( key = {'retweeted_status.id': True},
condition = {'entities.hashtags.text': regexp,'retweeted_status.id': {'$ne': None}},
initial = {'count': 0},
reduce = 'function(doc, prev) {prev.count += 1}')
return grpd
top_retweets = sorted(mongotools.get_retweets('df10'),key=itemgetter('count'),reverse=True)[0:10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment