How to use the apraw.models.helpers.comment_forrest.CommentForrest 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
"""
        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:
            return MoreComments(self._reddit, item["data"], self._link_id)
        else:
            return aPRAWBase(self._reddit, item["data"] if "data" in item else item)
github Dan6erbond / aPRAW / apraw / models / reddit / comment.py View on Github external
def _update(self, _data: Union[List, Dict[str, Any]]):
        """
        Update the base with new information.

        Parameters
        ----------
        _data: Dict
            The data obtained from the API.
        """

        if isinstance(_data, dict) or isinstance(_data, list):
            data = _data if isinstance(_data, dict) else _data[0]["data"]
            if isinstance(_data, list):
                from ..helpers.comment_forrest import CommentForrest
                self.replies = CommentForrest(self._reddit, _data[1]["data"], data["link_id"])

            self._data = data

            d = snake_case_keys(data)
            if "created_utc" in d:
                d["created_utc"] = datetime.utcfromtimestamp(d["created_utc"])
            self._data_attrs.update([k for k in d if not hasattr(self, k)])
            updates = [{"name": k, "value": v} for (k, v) in d.items() if not hasattr(self, k) or k in self._data_attrs]

            if "link_id" in d and "id" in d and "subreddit" in d:
                link_id = d["link_id"].replace(self._reddit.link_kind + "_", "")
                url = API_PATH["comment"].format(sub=d["subreddit"], submission=link_id, id=d["id"])
                updates.append({"name": "url", "value": url})
            elif "permalink" in d:
                url = "https://www.reddit.com" + d["permalink"]
                updates.append({"name": "url", "value": url})
github Dan6erbond / aPRAW / apraw / models / reddit / submission.py View on Github external
def _update(self, _data: Union[List, Dict[str, Any]]):
        """
        Update the base with new information.

        Parameters
        ----------
        _data: Dict
            The data obtained from the API.
        """
        if isinstance(_data, dict) or isinstance(_data, list):
            if isinstance(_data, dict):
                data = _data
            else:
                from ..helpers.comment_forrest import CommentForrest
                self.comments = CommentForrest(self._reddit, _data[1]["data"], self.fullname)
                data = _data[0]["data"]["children"][0]

            data["original_content"] = data.get("is_original_content", False)
            super()._update(data)
        else:
            raise ValueError("data is not of type 'dict' or 'list'.")