本文整理汇总了Python中Search.buildAnimeReply方法的典型用法代码示例。如果您正苦于以下问题:Python Search.buildAnimeReply方法的具体用法?Python Search.buildAnimeReply怎么用?Python Search.buildAnimeReply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search.buildAnimeReply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import Search [as 别名]
# 或者: from Search import buildAnimeReply [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
#.........这里部分代码省略.........
示例2: process_comment
# 需要导入模块: import Search [as 别名]
# 或者: from Search import buildAnimeReply [as 别名]
def process_comment(comment, is_edit=False):
#Anime/Manga requests that are found go into separate arrays
animeArray = []
mangaArray = []
lnArray = []
#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
if re.search('({!stats.*?}|{{!stats.*?}}|<!stats.*?>|<<!stats.*?>>)', comment.body, re.S) is not None:
username = re.search('[uU]\/([A-Za-z0-9_-]+?)(>|}|$)', comment.body, re.S)
subreddit = re.search('[rR]\/([A-Za-z0-9_]+?)(>|}|$)', comment.body, re.S)
if username:
commentReply = CommentBuilder.buildStatsComment(username=username.group(1))
elif subreddit:
commentReply = CommentBuilder.buildStatsComment(subreddit=subreddit.group(1))
else:
commentReply = CommentBuilder.buildStatsComment()
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.
#Counts the number of expanded results vs total results. If it's not just a single expanded result, they all get turned into normal requests.
numOfRequest = 0
numOfExpandedRequest = 0
forceNormal = False
for match in re.finditer("\{{2}([^}]*)\}{2}|\<{2}([^>]*)\>{2}", comment.body, re.S):
numOfRequest += 1
numOfExpandedRequest += 1
for match in re.finditer("(?<=(?<!\{)\{)([^\{\}]*)(?=\}(?!\}))|(?<=(?<!\<)\<)([^\<\>]*)(?=\>(?!\>))", comment.body, re.S):
numOfRequest += 1
if (numOfExpandedRequest >= 1) and (numOfRequest > 1):
forceNormal = True
#Expanded Anime
for match in re.finditer("\{{2}([^}]*)\}{2}", comment.body, re.S):
reply = ''
if (forceNormal) or (str(comment.subreddit).lower() in disableexpanded):
reply = Search.buildAnimeReply(match.group(1), False, comment)
else:
reply = Search.buildAnimeReply(match.group(1), True, comment)
if (reply is not None):
animeArray.append(reply)
#Normal Anime
for match in re.finditer("(?<=(?<!\{)\{)([^\{\}]*)(?=\}(?!\}))", comment.body, re.S):
reply = Search.buildAnimeReply(match.group(1), False, comment)
if (reply is not None):
animeArray.append(reply)
#Expanded Manga
#NORMAL EXPANDED
for match in re.finditer("\<{2}([^>]*)\>{2}(?!(:|\>))", comment.body, re.S):
reply = ''
if (forceNormal) or (str(comment.subreddit).lower() in disableexpanded):
reply = Search.buildMangaReply(match.group(1), False, comment)
else:
reply = Search.buildMangaReply(match.group(1), True, comment)
if (reply is not None):
mangaArray.append(reply)
#AUTHOR SEARCH EXPANDED
for match in re.finditer("\<{2}([^>]*)\>{2}:\(([^)]+)\)", comment.body, re.S):
reply = ''
if (forceNormal) or (str(comment.subreddit).lower() in disableexpanded):
reply = Search.buildMangaReplyWithAuthor(match.group(1), match.group(2), False, comment)
else:
reply = Search.buildMangaReplyWithAuthor(match.group(1), match.group(2), True, comment)
if (reply is not None):
mangaArray.append(reply)
#Normal Manga
#NORMAL
for match in re.finditer("(?<=(?<!\<)\<)([^\<\>]+)\>(?!(:|\>))", comment.body, re.S):
reply = Search.buildMangaReply(match.group(1), False, comment)
if (reply is not None):
mangaArray.append(reply)
#AUTHOR SEARCH
for match in re.finditer("(?<=(?<!\<)\<)([^\<\>]*)\>:\(([^)]+)\)", comment.body, re.S):
reply = Search.buildMangaReplyWithAuthor(match.group(1), match.group(2), False, comment)
if (reply is not None):
mangaArray.append(reply)
#.........这里部分代码省略.........