當前位置: 首頁>>代碼示例>>Python>>正文


Python Reddit.doLinkPost方法代碼示例

本文整理匯總了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)
開發者ID:icedvariables,項目名稱:quickreddit,代碼行數:59,代碼來源:qreddit.py


注:本文中的reddit.Reddit.doLinkPost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。