By: Dallaswebdevelopment.net
Date Created: April 11, 2018, 11:51 p.m.

This is a visualization of the post and submission activities of the users that post in the /r/forhire subreddit. This intro will mainly detail the details of this visualization. The sample size of this visualization is 710 users from the last 500 posts of this subreddit. Default subreddits were omitted, and subreddits with less than 30 submission frequency points or 150 comment frequency points (added up points of how many times a user commented or submitted a post in a given subreddit) were omitted.  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):
    try:
        if s.author.name not in users:
	    users.append(s.author.name)
    except:
	print 'Nonetype object has no attribute name'
    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)