def __init__(self, subredditList): self.subredditList = subredditList self.requestHandler = RequestHandler() #Set up reddit self.reddit = praw.Reddit(client_id=Config.appid, client_secret=Config.appsecret, user_agent=Config.useragent, username=Config.username, password=Config.password) print("Connected to Reddit") self.submissionProcessor = SubmissionProcessor(self.reddit, subredditList, self.requestHandler) self.submissionsLastProcessed = 0 self.updateTime = time.time()
def __init__(self, subredditList): self.subredditList = subredditList self.requestHandler = RequestHandler() #Set up reddit self.reddit = praw.Reddit(Config.useragent) self.reddit.set_oauth_app_info(client_id=Config.appid, client_secret=Config.appsecret, redirect_uri=Config.redirecturi) self.reddit.refresh_access_information(Config.refreshtoken) print("Connected to Reddit") self.submissionProcessor = SubmissionProcessor(self.reddit, subredditList, self.requestHandler) self.submissionsLastProcessed = 0 self.updateTime = time.time()
class YugiohLinkBot(object): def __init__(self, subredditList): self.subredditList = subredditList self.requestHandler = RequestHandler() #Set up reddit self.reddit = praw.Reddit(Config.useragent) self.reddit.set_oauth_app_info(client_id=Config.appid, client_secret=Config.appsecret, redirect_uri=Config.redirecturi) self.reddit.refresh_access_information(Config.refreshtoken) print("Connected to Reddit") self.submissionProcessor = SubmissionProcessor(self.reddit, subredditList, self.requestHandler) self.submissionsLastProcessed = 0 self.updateTime = time.time() def run(self): try: print("Starting stream") commentStream = praw.helpers.comment_stream(self.reddit, self.subredditList, limit=1000, verbosity=0) for comment in commentStream: if ((time.time() - self.updateTime) > Config.tcgUpdateInterval * 60 * 60): DatabaseHandler.updateTCGCardlist() self.updateTime = time.time() if ((time.time() - self.submissionsLastProcessed) > Config.submissionProcessingInterval * 60 * 60): self.submissionProcessor.processSubmissions(100) self.submissionsLastProcessed = time.time() #print("Found comment") #If we've already seen this comment, ignore it if DatabaseHandler.commentExists(comment.id): continue #If the post has been deleted, getting the author will return an error try: author = comment.author.name except Exception as e: continue #If this is one of our own comments, ignore it if (author == 'YugiohLinkBot'): continue reply = self.requestHandler.buildResponse(comment.body) try: if reply: cards = re.findall('\[\*\*(.+?)\*\*\]\(', reply) for card in cards: DatabaseHandler.addRequest(card, author, comment.subreddit) if("VENT THREAD" in comment.link_title): reply = self.submissionProcessor.convertCase(True, reply) elif("happiness thread" in comment.link_title): reply = self.submissionProcessor.convertCase(False, reply) DatabaseHandler.addComment(comment.id, author, comment.subreddit, True) comment.reply(reply) print("Comment made.\n") else: if ('{' in comment.body and '}' in comment.body): print('') DatabaseHandler.addComment(comment.id, author, comment.subreddit, False) except Exception as e: print("Reddit probably broke when replying:" + str(e) + '\n') except Exception as e: print("Error with comment stream: " + str(e)) traceback.print_exc()
class YugiohLinkBot(object): def __init__(self, subredditList): self.subredditList = subredditList self.requestHandler = RequestHandler() #Set up reddit self.reddit = praw.Reddit(client_id=Config.appid, client_secret=Config.appsecret, user_agent=Config.useragent, username=Config.username, password=Config.password) print("Connected to Reddit") self.submissionProcessor = SubmissionProcessor(self.reddit, subredditList, self.requestHandler) self.submissionsLastProcessed = 0 self.updateTime = time.time() def run(self): try: print("Starting stream") commentStream = self.reddit.subreddit( self.subredditList).stream.comments() for comment in commentStream: if ((time.time() - self.updateTime) > Config.tcgUpdateInterval * 60 * 60): DatabaseHandler.updateTCGCardlist() self.updateTime = time.time() if ((time.time() - self.submissionsLastProcessed) > Config.submissionProcessingInterval * 60 * 60): self.submissionProcessor.processSubmissions(100) self.submissionsLastProcessed = time.time() #print("Found comment") #If we've already seen this comment, ignore it if DatabaseHandler.commentExists(comment.id): continue #If the post has been deleted, getting the author will return an error try: author = comment.author.name except Exception as e: continue #If this is one of our own comments, ignore it if (author == 'YGOLinkBot'): continue reply = self.requestHandler.buildResponse(comment.body) try: if reply: cards = re.findall(r'\[\*\*(.+?)\*\*\]\(', reply) for card in cards: DatabaseHandler.addRequest(card, author, comment.subreddit) if ("VENT THREAD" in comment.link_title): reply = self.submissionProcessor.convertCase( True, reply) elif ("happiness thread" in comment.link_title): reply = self.submissionProcessor.convertCase( False, reply) comment.reply(reply) DatabaseHandler.addComment(comment.id, author, comment.subreddit, True) print("Comment made.\n") else: if ('{' in comment.body and '}' in comment.body): print('') DatabaseHandler.addComment(comment.id, author, comment.subreddit, False) except Exception as e: SendErrorMail(e, traceback.format_exc()) print("Reddit probably broke when replying:" + str(e) + '\n') except Exception as e: SendErrorMail(e, traceback.format_exc()) print(e) pass