本文整理汇总了Python中DatabaseHandler.commentExists方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.commentExists方法的具体用法?Python DatabaseHandler.commentExists怎么用?Python DatabaseHandler.commentExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.commentExists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [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()
示例2: process_pms
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [as 别名]
def process_pms():
for msg in reddit.get_unread(limit=None):
if (msg.subject == 'username mention'):
if (('{' and '}') in msg.body) or (('<' and '>') in msg.body):
try:
if str(msg.subreddit).lower() in exiled:
print('Edit request from exiled subreddit: ' + str(msg.subreddit) + '\n')
msg.mark_as_read()
continue
mentionedComment = reddit.get_info(thing_id=msg.name)
mentionedComment.refresh()
if not (DatabaseHandler.commentExists(mentionedComment.id)):
if str(mentionedComment.subreddit).lower() in Config.subredditlist:
continue
replies = mentionedComment.replies
ownComments = []
commentToEdit = None
for reply in replies:
if (reply.author.name == 'Roboragi'):
ownComments.append(reply)
for comment in ownComments:
if 'http://www.reddit.com/r/Roboragi/wiki/index' in comment.body:
commentToEdit = comment
commentReply = process_comment(mentionedComment, True)
try:
if (commentReply):
if commentToEdit:
commentToEdit.edit(commentReply)
print('Comment edited.\n')
else:
mentionedComment.reply(commentReply)
print('Comment made.\n')
except praw.errors.Forbidden:
print('Edit equest from banned subreddit: ' + str(msg.subreddit) + '\n')
msg.mark_as_read()
except Exception as e:
print(e)
示例3: isValidSubmission
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [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
示例4: isValidComment
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [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
示例5: processSubmissions
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [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')
示例6: start
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [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)
示例7: start
# 需要导入模块: import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler import commentExists [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
#.........这里部分代码省略.........