reddit.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:palmtree5-cogs 作者: palmtree5 项目源码 文件源码
def subreddit_top(self, ctx, subreddit: str, post_count: int=3):
        """Command for getting subreddit's top posts"""
        if post_count <= 0 or post_count > 100:
            await self.bot.say("Sorry, I can't do that")
        else:
            url = "https://oauth.reddit.com/r/{}/top".format(subreddit)
            url += "?limit=" + str(post_count)
            headers = {
                    "Authorization": "bearer " + self.access_token,
                    "User-Agent": "Red-DiscordBotRedditCog/0.1 by /u/palmtree5"
                }
            async with aiohttp.get(url, headers=headers) as req:
                resp_json = await req.json()
            if "data" not in resp_json and resp_json["error"] == 403:
                await self.bot.say("Sorry, the currently authenticated account does not have access to that subreddit")
                return
            resp_json = resp_json["data"]["children"]
            await self.post_menu(ctx, resp_json, page=0, timeout=30)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号