By: Dallaswebdevelopment.net
Date Created: April 10, 2018, 1 a.m.

This is a visualization of the post and comment activity of people who post in /r/Entrepreneur. This intro will mainly detail the details of this visualization. The sample size of this visualization is 396 users from the last 50 posts of this subreddit. Default subreddits were omitted, and subreddits with less than 15 submission frequency points or 100 comment frequency points (added up points of how many times a user commented or submitted a post in a given subreddit) were omitted. This is part one of the series "The Habits of Reddit's Entrepreneurs"; part 2 will be a visualization of /r/startups, which will be completed when I get back home. The code to get the data is below (and I have open sourced the code to visualize the data at my github repository https://github.com/mike-johnson-jr, as well as the code to get the data, in the same place)


import sys
import praw
import json
users = []
submissions = []

r = praw.Reddit(
    user_agent='changeme',
    client_id='changeme', 
    client_secret='changeme',
    username='changeme',
    password='changeme'
)

subreddit = r.subreddit(sys.argv[1])
#get submission object ids
for i,submission in enumerate(subreddit.hot(limit=50)):
    print 'getting submission object %s' % (i)
    submissions.append(
        r.submission(id=submission.id)
    )

comments = []
for i,s in enumerate(submissions):
    print 'getting users for commenters in submission %s of %s' % (
        i, 
        len(submissions)
    )
    for c in s.comments.list():
	try:
	    if c.author.name not in users:
		#get user of each comment in thread
		users.append(c.author.name)
	except:
	    print 'Nonetype object has no attribute name'
		
kb_submissions = {}
kb_comments = {}
for idx,username in enumerate(users):
    try:
	print 'getting info for %s, %s of %s' % (username,idx,len(users))
	user = r.redditor(username)
	submissions = user.submissions.new(limit=None)
	comments = user.comments.new(limit=None)
	for s in submissions:
	    subreddit = s.subreddit.display_name
	    kb_submissions[subreddit] = (
		kb_submissions.get(subreddit, 0) + 1
	    )
	for c in comments:
	    subreddit = c.subreddit.display_name
	    kb_comments[subreddit] = (
		kb_comments.get(subreddit, 0) + 1
	    )
    except:
	print 'user deleted'

karma_by_subreddit = {
    'submissions':kb_submissions,
    'comments':kb_comments,
    'users':users,
}
#save object to disk as json 
with open('data.json','w') as fp:
    json.dump(karma_by_subreddit,fp)