Created
April 4, 2015 03:35
-
-
Save httpNick/6d81d4b95591f8426d17 to your computer and use it in GitHub Desktop.
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
__author__ = 'httpnick' | |
import praw | |
from socketIO_client import SocketIO, LoggingNamespace | |
user_exists_in_db = false | |
def getInHereResponse(*args): | |
if (args[0]): | |
user_exists_in_db = true | |
else: | |
user_exists_in_db = false | |
r = praw.Reddit(user_agent='Testing My First Reddit Bot by /u/HelioOne v.01') | |
while True: | |
sub = r.get_subreddit('random') | |
submissions = sub.get_hot(limit=1000) | |
print("Trying Sub: "+sub.display_name) | |
for x in submissions: | |
com = praw.helpers.flatten_tree(x.comments) | |
for y in com: | |
try: | |
user = r.get_redditor(y.author) | |
username = str(y.author) | |
com = list() | |
sub = list() | |
vote = list() | |
flair = list() | |
print("\tTrying User: "+username) | |
except AttributeError: | |
continue | |
for comments in user.get_comments(limit=1000): | |
com.append(comments.body) | |
sub.append(comments.subreddit.display_name) | |
vote.append(comments.score) | |
flair.append(comments.author_flair_text) | |
SocketIO = SocketIO('71.231.103.140', 8888, LoggingNamespace) | |
socketIO.emit('isInHere', username) | |
socketIO.on('isInHereResponse', getInHereResponse) | |
if len(com) > 250 and not user_exists_in_db: | |
print("\tFinished With User And Attempting Emit") | |
post = {'username': username, 'comments': com, 'sub': sub, 'vote': vote, 'flair': flair} | |
try: | |
socketIO.emit('insert', post) | |
socketIO.wait(seconds=1) | |
socketIO.disconnect() | |
print("\t\tUser Successfully Emitted\n") | |
except ConnectionError as e: | |
print("\t\tEmit Failed\n") | |
continue | |
except TimeoutError as e: | |
print("\t\tTimed Out\n") | |
continue | |
else: | |
print("\t\tUser Data Too Small; Not Bothering\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment