Skip to content

Instantly share code, notes, and snippets.

@neilkod
Created December 16, 2010 17:15
Show Gist options
  • Save neilkod/743679 to your computer and use it in GitHub Desktop.
Save neilkod/743679 to your computer and use it in GitHub Desktop.
Returning the ids of the top-10 most retweeted tweets
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
n = 10
srtd = sorted(mongotools.get_retweets('df10'),key=itemgetter('count'),reverse=True)
top_retweets = srtd[0:n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment