本文整理汇总了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)
示例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
#.........这里部分代码省略.........