当前位置: 首页>>代码示例>>Python>>正文


Python Reddit.doTextPost方法代码示例

本文整理汇总了Python中reddit.Reddit.doTextPost方法的典型用法代码示例。如果您正苦于以下问题:Python Reddit.doTextPost方法的具体用法?Python Reddit.doTextPost怎么用?Python Reddit.doTextPost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reddit.Reddit的用法示例。


在下文中一共展示了Reddit.doTextPost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from reddit import Reddit [as 别名]
# 或者: from reddit.Reddit import doTextPost [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)
开发者ID:icedvariables,项目名称:quickreddit,代码行数:59,代码来源:qreddit.py


注:本文中的reddit.Reddit.doTextPost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。