Skip to content

Instantly share code, notes, and snippets.

@dpenfoldbrown
Created August 27, 2013 20:13
Show Gist options
  • Save dpenfoldbrown/6358546 to your computer and use it in GitHub Desktop.
Save dpenfoldbrown/6358546 to your computer and use it in GitHub Desktop.
User count aggregate things (# tweets, # urls, etc)
import pymongo
# Set up mongo DB here (get client, get database, get collection
client = MongoClient("smapp", 27011)
dbh = client['GunControl']
collection = dbh['GunTweetUsers_zephyr']
url_count = {}
tweet_count = {}
for user in collection.find():
tweet_count[user['id']] = 0
tweet_count[user['id']] += len(user['tweets'])
url_count[user['id']] = 0
for tweet in in user['tweets']:
url_count[user['id']] += len(tweet['urls'])
# Get url and tweet count lists in order
users = url_count.keys()
users.sort()
urlcountlist = []
for user in users:
urlcountlist.append(url_count[user])
tweetcountlst = []
for user in users:
tweetcountlist.append(tweet_count[user])
matplotlib.plot(urlcountlist, tweetcountlist, 'ro')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment