How to use the apraw.models.reddit.submission.Submission function in aPRAW

To help you get started, we’ve selected a few aPRAW examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dan6erbond / aPRAW / apraw / models / reddit / listing.py View on Github external
The item's index.

        Returns
        -------
        item: aPRAWBase
            The searched item.
        """
        item = getattr(self, self.CHILD_ATTRIBUTE)[index]

        if isinstance(item, aPRAWBase):
            return item

        if "page" in item:
            return WikipageRevision(self._reddit, item)
        elif item["kind"] == self._reddit.link_kind:
            return Submission(self._reddit, item["data"], subreddit=self._subreddit)
        elif item["kind"] == self._reddit.subreddit_kind:
            return Subreddit(self._reddit, item["data"])
        elif item["kind"] == self._reddit.comment_kind:
            if item["data"]["replies"] and item["data"]["replies"]["kind"] == self._reddit.listing_kind:
                from ..helpers.comment_forrest import CommentForrest
                replies = CommentForrest(self._reddit, item["data"]["replies"]["data"], item["data"]["link_id"])
            else:
                replies = []
            return Comment(self._reddit, item["data"], subreddit=self._subreddit, replies=replies)
        elif item["kind"] == self._reddit.modaction_kind:
            return ModAction(self._reddit, item["data"], self._subreddit)
        elif item["kind"] == self._reddit.message_kind:
            return Message(self._reddit, item["data"])
        elif item["kind"] == self._reddit.listing_kind:
            return Listing(self._reddit, item["data"])
        elif item["kind"] == self._reddit.more_kind:
github Dan6erbond / aPRAW / apraw / models / reddit / comment.py View on Github external
async def fetch(self):
        """
        Fetch this item's information from a suitable API endpoint.

        Returns
        -------
        self: Comment
            The ``Comment`` model with updated data.
        """
        if ("link_id" in self._data and "id" in self._data and "subreddit" in self._data) or "permalink" in self._data:
            permalink = self._data["permalink"] if "permalink" in self._data else API_PATH["comment"].format(
                sub=self._data["subreddit"], submission=self._data["link_id"].replace(self._reddit.link_kind + "_", ""),
                id=self._data["id"])
            resp = await self._reddit.get_request(permalink)
            from .submission import Submission
            self._submission = Submission(self._reddit, resp[0]["data"]["children"][0]["data"])
            return self._update(resp[1]["data"]["children"][0]["data"])
        elif "id" in self._data:
            resp = await self._reddit.get_request(API_PATH["info"],
                                                  id=prepend_kind(self._data["id"], self._reddit.comment_kind))
            return self._update(resp["data"]["children"][0]["data"])
        else:
            raise ValueError(f"No data available to make request URL: {self._data}")
github Dan6erbond / aPRAW / apraw / models / reddit / comment.py View on Github external
async def submission(self) -> 'Submission':
        """
        Retrieve the submission this comment was made in as a :class:`~apraw.models.Submission`.

        Returns
        -------
        submission: Submission
            The submission this comment was made in.
        """
        if self._submission is None:
            link = await self._reddit.get_request(API_PATH["info"], id=self._data["link_id"])
            from .submission import Submission
            self._submission = Submission(
                self._reddit, link["data"]["children"][0]["data"])
        return self._submission
github Dan6erbond / aPRAW / apraw / models / subreddit / subreddit.py View on Github external
raise ValueError("A url was expected")
        if kind == SubmissionKind.SELF and not text:
            raise ValueError("A text body was expected")

        resp = await self._reddit.post_request(API_PATH["submit"], **{
            "sr": str(self),
            "title": title,
            "kind": kind.value,
            "url": url,
            "text": text,
            "nsfw": kwargs.get("nsfw", False),
            "resubmit": kwargs.get("resubmit", False),
            "spoiler": kwargs.get("spoiler", False)
        })

        submission = Submission(self._reddit, {"id": resp["json"]["data"]["id"]})
        await submission.fetch()

        return submission