当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseHandler.addComment方法代码示例

本文整理汇总了Python中DatabaseHandler.addComment方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.addComment方法的具体用法?Python DatabaseHandler.addComment怎么用?Python DatabaseHandler.addComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseHandler的用法示例。


在下文中一共展示了DatabaseHandler.addComment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]
    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()
开发者ID:Nihilate,项目名称:YugiohLinkBot,代码行数:58,代码来源:YugiohLinkBot.py

示例2: isValidSubmission

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]
def isValidSubmission(submission):
    try:
        if (DatabaseHandler.commentExists(submission.id)):
            return False

        try:
            if (submission.author.name == 'Roboragi'):
                DatabaseHandler.addComment(submission.id, submission.author.name, submission.subreddit, False)
                return False
        except:
            pass

        return True
        
    except:
        traceback.print_exc()
        return False
开发者ID:Decker108,项目名称:Roboragi,代码行数:19,代码来源:Search.py

示例3: isValidComment

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]
def isValidComment(comment, reddit):
    try:
        if (DatabaseHandler.commentExists(comment.id)):
            return False

        try:
            if (comment.author.name == USERNAME):
                DatabaseHandler.addComment(comment.id, comment.author.name, comment.subreddit, False)
                return False
        except:
            pass

        return True
        
    except:
        traceback.print_exc()
        return False
开发者ID:Nihilate,项目名称:Roboragi,代码行数:19,代码来源:Search.py

示例4: processSubmissions

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]
    def processSubmissions(self, num):
        subreddits = self.reddit.get_subreddit(self.subredditList)
        
        for submission in subreddits.get_new(limit=num):
            #If we've already seen this submission, ignore it
            if DatabaseHandler.commentExists(submission.id):
                continue

            #If the post has been deleted, getting the author will return an error
            try:
                author = submission.author.name
            except Exception as e:
                continue

            #If this is one of our own submissions, ignore it
            if (author == 'YugiohLinkBot'):
                continue

            reply = self.requestHandler.buildResponse(submission.selftext)

            try:
                if reply:
                    cards = re.findall('\[\*\*(.+?)\*\*\]\(', reply)
                    for card in cards:
                        DatabaseHandler.addRequest(card, author, submission.subreddit)

                    if("VENT THREAD" in submission.title):
                        reply = self.convertCase(True, reply)
                    elif("happiness thread" in submission.title):
                        reply = self.convertCase(False, reply)

                    DatabaseHandler.addComment(submission.id, author, submission.subreddit, True)
                    submission.add_comment(reply)
                    print("Comment made.\n")
                else:
                    if ('{' in submission.selftext and '}' in submission.selftext):
                        print('')
                    DatabaseHandler.addComment(submission.id, author, submission.subreddit, False)
            except Exception as e:
                traceback.print_exc()
                print("Reddit probably broke when replying:" + str(e) + '\n')
开发者ID:Nihilate,项目名称:YugiohLinkBot,代码行数:43,代码来源:SubmissionProcessor.py

示例5: start

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]
def start():
    print('Starting comment stream:')
    last_checked_pms = time.time()

    #This opens a constant stream of comments. It will loop until there's a major error (usually this means the Reddit access token needs refreshing)
    comment_stream = praw.helpers.comment_stream(reddit, SUBREDDITLIST, limit=250, verbosity=0)

    for comment in comment_stream:

        # check if it's time to check the PMs
        if (time.time() - last_checked_pms) > TIME_BETWEEN_PM_CHECKS:
            process_pms()
            last_checked_pms = time.time()

        #Is the comment valid (i.e. it's not made by Roboragi and I haven't seen it already). If no, try to add it to the "already seen pile" and skip to the next comment. If yes, keep going.
        if not (Search.isValidComment(comment, reddit)):
            try:
                if not (DatabaseHandler.commentExists(comment.id)):
                    DatabaseHandler.addComment(comment.id, comment.author.name, comment.subreddit, False)
            except:
                pass
            continue

        process_comment(comment)
开发者ID:Nihilate,项目名称:Roboragi,代码行数:26,代码来源:AnimeBot.py

示例6: start

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]
def start():
    print('Starting comment stream:')

    #This opens a constant stream of comments. It will loop until there's a major error (usually this means the Reddit access token needs refreshing)
    comment_stream = praw.helpers.comment_stream(reddit, subredditlist, limit=250, verbosity=0)

    for comment in comment_stream:

        #Is the comment valid (i.e. it's not made by Roboragi and I haven't seen it already). If no, try to add it to the "already seen pile" and skip to the next comment. If yes, keep going.
        if not (Search.isValidComment(comment, reddit)):
            try:
                if not (DatabaseHandler.commentExists(comment.id)):
                    DatabaseHandler.addComment(comment.id, comment.author.name, comment.subreddit, False)
            except:
                pass
            continue

        #Anime/Manga requests that are found go into separate arrays
        animeArray = []
        mangaArray = []

        #The "hasExpandedRequest" variable puts a stop on any other requests (since you can only have one expanded request in a comment)
        hasExpandedRequest = False

        #ignores all "code" markup (i.e. anything between backticks)
        comment.body = re.sub(r"\`(?s)(.*?)\`", "", comment.body)
        
        #This checks for requests. First up we check all known tags for the !stats request
        # Assumes tag begins and ends with a whitespace OR at the string beginning/end
        if re.search('(^|\s)({!stats}|{{!stats}}|<!stats>|<<!stats>>)($|\s|.)', comment.body, re.S) is not None:
            commentReply = CommentBuilder.buildStatsComment(comment.subreddit)
        else:

            #The basic algorithm here is:
            #If it's an expanded request, build a reply using the data in the braces, clear the arrays, add the reply to the relevant array and ignore everything else.
            #If it's a normal request, build a reply using the data in the braces, add the reply to the relevant array.

            #Expanded Anime
            for match in re.finditer("\{{2}([^}]*)\}{2}", comment.body, re.S):
                if (str(comment.subreddit).lower() not in disableexpanded):
                    if hasExpandedRequest:
                        break
                    reply = Search.buildAnimeReply(match.group(1), True, comment)

                    if not (reply is None):
                        hasExpandedRequest = True
                        animeArray = [reply]
                        mangaArray = []
                else:
                    if hasExpandedRequest:
                        break
                    reply = Search.buildAnimeReply(match.group(1), False, comment)

                    if (reply is not None) and (len(animeArray) + len(mangaArray) < 10):
                        animeArray.append(reply)

            #Normal Anime  
            for match in re.finditer("(?<=(?<!\{)\{)([^\{\}]*)(?=\}(?!\}))", comment.body, re.S):
                if hasExpandedRequest:
                    break
                reply = Search.buildAnimeReply(match.group(1), False, comment)

                if (reply is not None) and (len(animeArray) + len(mangaArray) < 10):
                    animeArray.append(reply)

            #Expanded Manga
            for match in re.finditer("\<{2}([^>]*)\>{2}", comment.body, re.S):
                if (str(comment.subreddit).lower() not in disableexpanded):
                    if hasExpandedRequest:
                        break;
                    reply = Search.buildMangaReply(match.group(1), True, comment)

                    if not (reply is None):
                        hasExpandedRequest = True
                        animeArray = []
                        mangaArray = [reply]
                else:
                    if hasExpandedRequest:
                        break
                    reply = Search.buildMangaReply(match.group(1), False, comment)

                    if (reply is not None) and (len(animeArray) + len(mangaArray) < 10):
                        mangaArray.append(reply)

            #Normal Manga
            for match in re.finditer("(?<=(?<!\<)\<)([^\<\>]*)(?=\>(?!\>))", comment.body, re.S):
                if hasExpandedRequest:
                    break
                reply = Search.buildMangaReply(match.group(1), False, comment)

                if (reply is not None) and (len(animeArray) + len(mangaArray) < 10):
                    mangaArray.append(reply)

                
            #Here is where we create the final reply to be posted

            #The final comment reply. We add stuff to this progressively.
            commentReply = ''

            #If we have anime AND manga in one reply we format stuff a little differently
#.........这里部分代码省略.........
开发者ID:mnmt,项目名称:Roboragi,代码行数:103,代码来源:AnimeBot.py

示例7: process_comment

# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import addComment [as 别名]

#.........这里部分代码省略.........

        #Expanded LN
        for match in re.finditer("\]{2}([^]]*)\[{2}", comment.body, re.S):
            reply = ''

            if (forceNormal) or (str(comment.subreddit).lower() in disableexpanded):
                reply = Search.buildLightNovelReply(match.group(1), False, comment)
            else:
                reply = Search.buildLightNovelReply(match.group(1), True, comment)                    

            if (reply is not None):
                lnArray.append(reply)

        #Normal LN  
        for match in re.finditer("(?<=(?<!\])\])([^\]\[]*)(?=\[(?!\[))", comment.body, re.S):
            reply = Search.buildLightNovelReply(match.group(1), False, comment)
            
            if (reply is not None):
                lnArray.append(reply)
            
        #Here is where we create the final reply to be posted

        #The final comment reply. We add stuff to this progressively.
        commentReply = ''

        #Basically just to keep track of people posting the same title multiple times (e.g. {Nisekoi}{Nisekoi}{Nisekoi})
        postedAnimeTitles = []
        postedMangaTitles = []
        postedLNTitles = []

        #Adding all the anime to the final comment. If there's manga too we split up all the paragraphs and indent them in Reddit markup by adding a '>', then recombine them
        for i, animeReply in enumerate(animeArray):
            if not (i is 0):
                commentReply += '\n\n'

            if not (animeReply['title'] in postedAnimeTitles):
                postedAnimeTitles.append(animeReply['title'])
                commentReply += animeReply['comment']
            

        if mangaArray:
            commentReply += '\n\n'

        #Adding all the manga to the final comment
        for i, mangaReply in enumerate(mangaArray):
            if not (i is 0):
                commentReply += '\n\n'
            
            if not (mangaReply['title'] in postedMangaTitles):
                postedMangaTitles.append(mangaReply['title'])
                commentReply += mangaReply['comment']

        if lnArray:
            commentReply += '\n\n'

        #Adding all the manga to the final comment
        for i, lnReply in enumerate(lnArray):
            if not (i is 0):
                commentReply += '\n\n'
            
            if not (lnReply['title'] in postedLNTitles):
                postedLNTitles.append(lnReply['title'])
                commentReply += lnReply['comment']

        #If there are more than 10 requests, shorten them all 
        if not (commentReply is '') and (len(animeArray) + len(mangaArray)+ len(lnArray) >= 10):
            commentReply = re.sub(r"\^\((.*?)\)", "", commentReply, flags=re.M)

    #If there was actually something found, add the signature and post the comment to Reddit. Then, add the comment to the "already seen" database.
    if commentReply is not '':
        '''if (comment.author.name == 'treborabc'):
            commentReply = '[No.](https://www.reddit.com/r/anime_irl/comments/4sba1n/anime_irl/d58xkha)'''
        
        commentReply += Config.getSignature(comment.permalink)

        commentReply += Reference.get_bling(comment.author.name)

        if is_edit:
            return commentReply
        else:
            try:
                comment.reply(commentReply)
                print("Comment made.\n")
            except praw.errors.Forbidden:
                print('Request from banned subreddit: ' + str(comment.subreddit) + '\n')
            except Exception:
                traceback.print_exc()

            try:
                DatabaseHandler.addComment(comment.id, comment.author.name, comment.subreddit, True)
            except:
                traceback.print_exc()
    else:
        try:
            if is_edit:
                return None
            else:
                DatabaseHandler.addComment(comment.id, comment.author.name, comment.subreddit, False)
        except:
            traceback.print_exc()
开发者ID:Nihilate,项目名称:Roboragi,代码行数:104,代码来源:AnimeBot.py


注:本文中的DatabaseHandler.addComment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。