Created
August 27, 2013 20:13
-
-
Save dpenfoldbrown/6358546 to your computer and use it in GitHub Desktop.
User count aggregate things (# tweets, # urls, etc)
This file contains 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
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