Python PRAW – 检查 redditor 是否是版主
在 Reddit 中,redditor 是给予用户的术语。版主是redditor,其任务是管理subreddit。在这里,我们将看到如何检查 redditor 是否是任何 subreddit 的版主。我们将使用Redditor
类的is_mod
属性来检查 redditor 是否是版主。
示例 1:考虑以下 redditor:
redditor 的用户名是:spez。
# importing the module
import praw
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = user_agent)
# the name of the redditor
redditor_name = "spez"
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
print("Is " + redditor_name + " a moderator? : " +
str(redditor.is_mod))
输出 :
Is spez a moderator? : True
示例 2:考虑以下 redditor:
redditor 的用户名是:AutoModerator
# importing the module
import praw
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = user_agent)
# the name of the redditor
redditor_name = "AutoModerator"
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
print("Is " + redditor_name + " an employee of Reddit? : " +
str(redditor.is_mod))
输出 :
Is AutoModerator a moderator? : True