本文整理汇总了Python中Actions.get_mods方法的典型用法代码示例。如果您正苦于以下问题:Python Actions.get_mods方法的具体用法?Python Actions.get_mods怎么用?Python Actions.get_mods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actions
的用法示例。
在下文中一共展示了Actions.get_mods方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_mods
# 需要导入模块: import Actions [as 别名]
# 或者: from Actions import get_mods [as 别名]
def update_mods(self, author=None):
"""
Update the internal mod-list (who can execute queries)
:param author: if specified, the bot will respond to this user to let them know success/failure
:return: None
"""
try:
mlist = [mod.name for mod in Actions.get_mods(self.praw, self.sub)]
if mlist is None or not len(mlist):
return False
# only update if it's valid
self.mod_list = mlist
self.last_mod_update = datetime.datetime.now()
if author is not None:
Actions.send_message(self.praw, author, u"RE: Modlist update", u"Success!")
return True
except Exception, e:
if author is not None:
Actions.send_message(self.praw, author, u"RE: Modlist update",
u"Error encountered, please try again later.")
logging.error(u"Could not update moderator list!")
self.log_error()
if __debug__:
logging.exception(e)
return False
示例2: test_get_moderators
# 需要导入模块: import Actions [as 别名]
# 或者: from Actions import get_mods [as 别名]
def test_get_moderators(r, sub):
print "Test Get Mods:"
mods = a.get_mods(r, sub)
if len([u for u in mods if any(name == u.name for name in ['arghdos', 'centralscruuutinizer'])]) == 2:
print "Passed"
return True
print "Failed"
return False
示例3: main
# 需要导入模块: import Actions [as 别名]
# 或者: from Actions import get_mods [as 别名]
def main():
cred = CRImport("credentials.cred")
db = sqlite3.connect('database.db', detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = db.cursor()
post_list = [post[0] for post in cursor.execute('select short_url from reddit_record where submitter is null').fetchall()]
praw = utilitymethods.create_multiprocess_praw(cred)
reddit = utilitymethods.get_subreddit(cred, praw, 'listentothis')
mods = [mod.name for mod in Actions.get_mods(praw, reddit)]
stride = 100
total_len = len(post_list)
count = 0
while len(post_list):
num_loaded = min(stride, len(post_list))
reddit_posts = Actions.get_by_ids(praw, post_list[:num_loaded])
update_list = []
print "{} / {}".format(count, total_len)
count += stride
for i, post in enumerate(reddit_posts):
#check
submitter = cursor.execute('select submitter from reddit_record where short_url = ?', (post_list[i],)).fetchone()[0]
if submitter is not None:
continue
assert(post_list[i] == post.name)
success = False
while not success:
try:
success = True
if Actions.is_deleted(post):
#check comments
found = False
for comment in post.comments:
if comment.distinguished == 'moderator':
if re.search(r'^(?:\*\*)?/u/', comment.body):
search = re.search(r'^(?:\*\*)?/u/([\w\d_\-\*]+)[,\s]', comment.body)
if search:
found = True
success = True
update_list.append((search.group(1), post_list[i]))
break
elif re.search(r'^All apologies /u/([\w\d_\-\*]+)[,\s]', comment.body):
search = re.search(r'^All apologies /u/([\w\d_\-\*]+)[,\s]', comment.body)
if search:
found = True
success = True
update_list.append((search.group(1), post_list[i]))
break
elif re.search(r'/u/([\w\d\*-_]+), your submission', comment.body):
search = re.search(r'/u/([\w\d\*-_]+), your submission', comment.body)
if search:
found = True
success = True
update_list.append((search.group(1), post_list[i]))
break
elif re.search(r'^Hey /u/([\w\d_\-\*]+)[,\s]', comment.body):
search = re.search(r'^Hey /u/([\w\d_\-\*]+)[,\s]', comment.body)
if search:
found = True
success = True
update_list.append((search.group(1), post_list[i]))
break
elif re.search(r'/u/([\w\d_\-\*]+)[,\s]', comment.body):
search = re.search(r'/u/([\w\d_\-\*]+)[,\s]', comment.body)
if search and 'evilnight' not in search.group(1):
print comment.body
print search.group(1)
if not found:
success = True
update_list.append((None, post_list[i]))
else:
success = True
update_list.append((post.author.name, post_list[i]))
if update_list[-1][0] is not None and update_list[-1][0].endswith(','):
print update_list[-1]
except Exception, e:
success = False
time.sleep(1)
assert (not any(val[0].endswith(',') for val in update_list if val[0] is not None))
post_list = post_list[num_loaded:]
cursor.executemany('update reddit_record set submitter = ? where short_url = ?', update_list)
db.commit()