Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
from typing import TYPE_CHECKING, Dict
from ..reddit.comment import Comment
from ..reddit.listing import Listing
from ..reddit.more_comments import MoreComments
from ..subreddit.subreddit import Subreddit
if TYPE_CHECKING:
from ...reddit import Reddit
class CommentForest(Listing):
def __init__(self, reddit: 'Reddit', data: Dict, link_id: str, subreddit: Subreddit = None):
super().__init__(reddit, data, subreddit, link_id=link_id)
self._comments_unfolded = []
async def replace_more(self):
if not self._comments_unfolded:
for item in self:
if isinstance(item, MoreComments):
comments = await item.comments()
for comment in comments:
if comment.replies:
await comment.replies.replace_more()
self._comments_unfolded.extend(comments)
elif isinstance(item, Comment):
if item.replies:
async def random(self):
"""
Retrieve a random submission from the subreddit.
Returns
-------
submission: Submission
A random submission from the subreddit.
"""
resp = await self._reddit.get_request(API_PATH["subreddit_random"].format(sub=self))
from ..reddit.listing import Listing
listing = Listing(self._reddit, data=resp[0]["data"], subreddit=self)
return next(listing)
return aPRAWBase(self._reddit, item["data"] if "data" in item else item)
@property
def last(self) -> aPRAWBase:
"""
Return the last item in the listing.
Returns
-------
item: aPRAWBase
The last item in the listing.
"""
return self[len(self) - 1] if len(self) > 0 else None
class MoreChildren(Listing):
CHILD_ATTRIBUTE = "things"