本文整理匯總了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)
#.........這裏部分代碼省略.........