本文整理汇总了Python中praw.Reddit.delete_flair方法的典型用法代码示例。如果您正苦于以下问题:Python Reddit.delete_flair方法的具体用法?Python Reddit.delete_flair怎么用?Python Reddit.delete_flair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类praw.Reddit
的用法示例。
在下文中一共展示了Reddit.delete_flair方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModUtils
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import delete_flair [as 别名]
class ModUtils(object):
"""Class that provides all the modutils functionality."""
def __init__(self, subreddit, site=None, user=None, pswd=None, verbose=None):
self.reddit = Reddit(str(self), site, disable_update_check=True)
self.reddit.config.decode_html_entities = True
self._logged_in = False
self._user = user
self._pswd = pswd
self.sub = self.reddit.get_subreddit(subreddit)
self.verbose = verbose
self._current_flair = None
def add_users(self, category):
"""Add users to 'banned', 'contributors', or 'moderators'."""
mapping = {"banned": "ban", "contributors": "make_contributor", "moderators": "make_moderator"}
if category not in mapping:
print("%r is not a valid option for --add" % category)
return
self.login()
func = getattr(self.sub, mapping[category])
print("Enter user names (any separation should suffice):")
data = sys.stdin.read().strip()
for name in re.split("[^A-Za-z0-9_]+", data):
func(name)
print("Added %r to %s" % (name, category))
def clear_empty(self):
"""Remove flair that is not visible or has been set to empty."""
for flair in self.current_flair():
if not flair["flair_text"] and not flair["flair_css_class"]:
print(self.reddit.delete_flair(self.sub, flair["user"]))
print("Removed flair for {0}".format(flair["user"]))
def current_flair(self):
"""Generate the flair, by user, for the subreddit."""
if self._current_flair is None:
self._current_flair = []
self.login()
if self.verbose:
print("Fetching flair list for %s" % self.sub)
for flair in self.sub.get_flair_list(limit=None):
self._current_flair.append(flair)
yield flair
else:
for item in self._current_flair:
yield item
def flair_template_sync(self, editable, limit, static, sort, use_css, use_text): # pylint: disable-msg=R0912
"""Synchronize templates with flair that already exists on the site.
:param editable: Indicates that all the options should be editable.
:param limit: The minimum number of users that must share the flair
before it is added as a template.
:param static: A list of flair templates that will always be added.
:param sort: The order to sort the flair templates.
:param use_css: Include css in the templates.
:param use_text: Include text in the templates.
"""
# Parameter verification
if not use_text and not use_css:
raise Exception("At least one of use_text or use_css must be True")
sorts = ("alpha", "size")
if sort not in sorts:
raise Exception("Sort must be one of: %s" % ", ".join(sorts))
# Build current flair list along with static values
counter = {}
if static:
for key in static:
if use_css and use_text:
parts = tuple(x.strip() for x in key.split(","))
if len(parts) != 2:
raise Exception(
"--static argument %r must have two "
"parts (comma separated) when using "
"both text and css." % parts
)
key = parts
counter[key] = limit
self.login()
if self.verbose:
sys.stdout.write("Retrieving current flair\n")
sys.stdout.flush()
for flair in self.current_flair():
if self.verbose:
sys.stdout.write(".")
sys.stdout.flush()
if use_text and use_css:
key = (flair["flair_text"], flair["flair_css_class"])
elif use_text:
key = flair["flair_text"]
else:
key = flair["flair_css_class"]
if key in counter:
counter[key] += 1
else:
#.........这里部分代码省略.........