本文整理匯總了Python中DatabaseManager.DatabaseManager.hasBotAlreadyReplied方法的典型用法代碼示例。如果您正苦於以下問題:Python DatabaseManager.hasBotAlreadyReplied方法的具體用法?Python DatabaseManager.hasBotAlreadyReplied怎麽用?Python DatabaseManager.hasBotAlreadyReplied使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DatabaseManager.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.hasBotAlreadyReplied方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from DatabaseManager import DatabaseManager [as 別名]
# 或者: from DatabaseManager.DatabaseManager import hasBotAlreadyReplied [as 別名]
class ReputationManager:
def __init__(self, subreddit, username, db_name, debug=False):
'''
initializer for the ReputationManager
pre: the subreddit it's going to manage in, and the name of the database
and if debug mode is turned on or not, default is False
post: the ReputationManager class is initialized
'''
user_agent = 'Reputation-Manager v1.2.1 /u/cutety'
self.r = praw.Reddit(user_agent=user_agent,log_requests=0)
self.o = OAuth2Util.OAuth2Util(self.r, print_log=False)
self.subreddit = subreddit
self.username = username
print('Initializing database...')
self.db = DatabaseManager(db_name)
# the functions are associated with the identifiers position in this list
# this is done so identifier can be changed at anytime and the same function
# will be done without having to change any other code
self.identifiers = ['!offer', '!accept', '!success', '!scam', '!report',
'!cancel', '!retract']
# configure logging
logging.basicConfig(filename='REPMLog.log',
level=logging.DEBUG,
format='%(asctime)s %(message)s')
self.debug = debug
def mainLoop(self):
'''
the main loop for running the bot
pre: None
post: The bot is running
'''
while True:
try:
self.checkForComments()
except Exception as e:
for frame in traceback.extract_tb(sys.exc_info()[2]):
fname,lineno,fn,text = frame
logging.debug('ERROR: {} on line {} in {}() in file{}'.format(e, lineno, fn, fname))
time.sleep(60)
def checkForComments(self):
'''
starts checking the comments for identifiers
pre: None
post: None
'''
print('Checking comments...')
comment_stream = praw.helpers.comment_stream(self.r, subreddit=self.subreddit)
for comment in comment_stream:
self.o.refresh()
for identifier in self.identifiers:
if identifier in str(comment) and not self.db.hasBotAlreadyReplied(comment.id):
# ignore it if it's just the bots comment
if str(comment.author) == self.username:
continue
# Do the correct task for the identifer in the comment
print('Doing task: {}'.format(identifier))
self._doTask(self.identifiers.index(identifier), comment)
# "Private" methods
def _doTask(self, task, comment):
'''
switcher for doing a task
pre: the task it needs to do, and a praw comment object
post: None
'''
if task == 0:
self._offerMade(comment)
elif task == 1:
self._acceptMade(comment)
elif task == 2:
self._successOnDeal(comment)
elif task == 3:
self._scamOnDeal(comment)
elif task == 4:
self._reportUser(comment)
elif task == 5 or task == 6:
self._cancelDeal(comment)
else:
self._replyWithError(comment, 'Err')
def _offerMade(self, comment):
#.........這裏部分代碼省略.........