Created
July 5, 2013 18:13
-
-
Save dmarx/5936250 to your computer and use it in GitHub Desktop.
Analysis of "super moderators" on reddit.com. Requires praw library and a "subreddits.txt" file populated with the names of subreddits the user wants to investigate moderators from.
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 praw, csv | |
from collections import defaultdict, Counter | |
# your userlogin information here. If you don't provide, the script will prompt | |
# you for it at the terminal, so no big deal either way. Just a convenience. | |
USERNAME = '' | |
PASSWORD= '' | |
useragent='getting moderators graph by /u/shaggorama' | |
r=praw.Reddit(useragent) | |
r.login(USERNAME,PASSWORD) | |
with open('subreddits.txt','r') as subreddits: | |
top_subreddits=subreddits.read().split() | |
# build the moderator-moderator edge list | |
edges = defaultdict(Counter) | |
for sub in top_subreddits: | |
print sub | |
mods=r.get_subreddit(sub).get_moderators() | |
# You can remove automderator from your data colelction entirely, or remove the node | |
# later on by modifying the output csv or from within your network analysis software. | |
#mods = [user.name for user in mods] | |
mods = [user.name for user in mods if user.name != 'AutoModerator'] | |
for p in mods: | |
for q in mods: | |
#if p!=q: # we don't need this to be a directional graph... | |
if p < q: # this will dedupe our edges, we just need to make sure our graph is interpreted as undirected. | |
edges[p][q]+=1 | |
fname = "moderator_edges.csv" | |
#print to csv | |
with open(fname,'wb') as f: | |
writer=csv.writer(f) | |
writer.writerow(["source","target","weight", "type"]) # header row | |
for m1, cntr in edges.iteritems(): | |
for m2, wt in cntr.iteritems(): | |
if wt > 1: # exclude edges that only share a single subreddit | |
writer.writerow([m1,m2,wt, "undirected"]) | |
# narrow in on biggest supermods clique | |
# This analysis is unnecessary manual | |
supermods = ['KennyLog-in', 'BritishEnglishPolice', 'maxwellhill', 'klyde', 'qgyh2'] | |
for mod in supermods: | |
#print mod | |
for sub in top_subreddits: | |
#print sub | |
mods=r.get_subreddit(sub).get_moderators() | |
mods = [user.name for user in mods if user.name != 'AutoModerator'] | |
if mod in mods: | |
print mod, sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment