Skip to content

Instantly share code, notes, and snippets.

@AlexNeises
Created February 28, 2017 23:04
Show Gist options
  • Save AlexNeises/e4b05e281b6d24b11d4765149fcba0f0 to your computer and use it in GitHub Desktop.
Save AlexNeises/e4b05e281b6d24b11d4765149fcba0f0 to your computer and use it in GitHub Desktop.
A python script to go through a list of subreddits, grab the hot 25 threads of each one, and crawl every comment with positive karma, while creating a json list of users who met the criteria.
import praw
client_id = 'XXXXXXXX'
client_secret = 'XXXXXXXX'
refresh_token = 'XXXXXXXX'
reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, refresh_token=refresh_token user_agent='Skrapr')
crawl_subreddits = ['sub1', 'sub2', 'sub3']
user_list = []
count = 0
for sub in crawl_subreddits:
print('Searching in r/' + str(sub))
try:
subreddit = reddit.subreddit(sub)
for submission in subreddit.hot(limit=25):
try:
count += 1
user_list.append(submission.author)
print('Users found: ' + str(count))
submission.comments.replace_more(limit=0)
all_comments = submission.comments.list()
for single_comment in all_comments:
try:
if single_comment.score > 0:
count += 1
user_list.append(single_comment.author)
print('Users found: ' + str(count))
except Exception as e:
print('Error: ' + str(e))
continue
except Exception as e:
print('Error: ' + str(e))
continue
except Exception as e:
print('Error: ' + str(e))
continue
print('Removing duplicate users...')
user_list = list(set(user_list))
print('Found ' + str(len(user_list)) + ' unique users.')
json_list = []
for usr in user_list:
json_list.append('"' + str(usr) + '":{"color":"yellow","tag":"Tag!"}')
userlist = open('users.json', 'wb')
userlist.write("{" + ",".join(json_list) + "}")
userlist.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment