本文整理汇总了Python中reddit.Reddit.doLinkPost方法的典型用法代码示例。如果您正苦于以下问题:Python Reddit.doLinkPost方法的具体用法?Python Reddit.doLinkPost怎么用?Python Reddit.doLinkPost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reddit.Reddit
的用法示例。
在下文中一共展示了Reddit.doLinkPost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from reddit import Reddit [as 别名]
# 或者: from reddit.Reddit import doLinkPost [as 别名]
class QReddit:
def __init__(self):
self.r = Reddit()
(self.options, args) = self.parseArguments()
if(len(args) < 1):
print "Please specify type of action (textpost, linkpost, viewsub, createuser)"
return
self.action = args[0]
if(self.options.username and self.options.password):
self.user = {"username":self.options.username, "password":self.options.password}
else:
try:
self.user = self.getUser()
except IOError:
print "No user was specified through --user and --password but could not find 'user.json'. Please either use createuser or use --user and --password."
sys.exit()
def parseArguments(self):
parser = optparse.OptionParser()
parser.add_option("-s", "--subreddit", help="Specify subreddit", dest="subreddit")
parser.add_option("-t", "--title", help="Specify title", dest="title")
parser.add_option("-b", "--body", help="Specify post body (for text post)", dest="body")
parser.add_option("-l", "--link", help="Specify post link (for link post)", dest="link")
parser.add_option("-u", "--user", help="Specify username", dest="username")
parser.add_option("-p", "--pass", help="Specify password", dest="password")
parser.add_option("-L", "--limit", help="Limit results (for view)", type="int", dest="limit")
parser.add_option("-i", "--postid", help="Specify post ID", dest="postid")
return parser.parse_args()
def performAction(self):
if(self.action == "textpost"):
self.r.doTextPost(self.options, self.user)
if(self.action == "linkpost"):
self.r.doLinkPost(self.options, self.user)
if(self.action == "viewsub"):
self.r.doViewsub(self.options)
if(self.action == "viewpost"):
self.r.doViewpost(self.options)
if(self.action == "createuser"):
self.createUser(self.options.username, self.options.password)
def getUser(self):
try:
with open("user.json") as f:
user = json.load(f)
except IOError:
raise e
return user
def createUser(self, username, password):
with open("user.json", "w") as f:
json.dump({"username":username, "password":password}, f)