當前位置: 首頁>>代碼示例>>Python>>正文


Python Search.isValidComment方法代碼示例

本文整理匯總了Python中Search.isValidComment方法的典型用法代碼示例。如果您正苦於以下問題:Python Search.isValidComment方法的具體用法?Python Search.isValidComment怎麽用?Python Search.isValidComment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Search的用法示例。


在下文中一共展示了Search.isValidComment方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start

# 需要導入模塊: import Search [as 別名]
# 或者: from Search import isValidComment [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

示例2: start

# 需要導入模塊: import Search [as 別名]
# 或者: from Search import isValidComment [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


注:本文中的Search.isValidComment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。