How to use the praw.models.Comment function in praw

To help you get started, we’ve selected a few praw 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 praw-dev / praw / tests / integration / models / reddit / test_comment.py View on Github external
def test_parent__comment(self):
        comment = Comment(self.reddit, "cklhv0f")
        with self.recorder.use_cassette("TestComment.test_parent__comment"):
            parent = comment.parent()
            parent.refresh()
            assert comment in parent.replies
        assert isinstance(parent, Comment)
        assert parent.fullname == comment.parent_id
github praw-dev / praw / tests / integration / models / reddit / test_comment.py View on Github external
def test_refresh__removed_comment(self):
        with self.recorder.use_cassette(
            "TestComment.test_refresh__removed_comment"
        ):
            with pytest.raises(ClientException) as excinfo:
                Comment(self.reddit, "dma3mi5").refresh()
        assert (
            "This comment does not appear to be in the comment tree",
        ) == excinfo.value.args
github GrafeasGroup / tor / test / generators.py View on Github external
def generate_comment(
    name="comment",
    submission=None,
    reply=None,
    parent=None,
    author=_missing,
    body="",
    subject="comment reply",
):
    comment = MagicMock(name=name, spec=praw.models.Comment)
    comment.kind = "t1"
    if author is _missing:
        author = generate_redditor().name
    comment.author = generate_redditor(username=author)
    comment.subject = subject
    if not submission:
        submission = generate_submission()
    comment.submission = submission
    comment.id = generate_reddit_id()
    comment.body = body
    if not parent:
        parent = submission
    comment.parent = MagicMock(return_value=parent)

    def make_comment(cmnt_body):
        if reply:
github praw-dev / praw / tests / integration / models / reddit / test_comment.py View on Github external
def test_refresh(self):
        comment = Comment(self.reddit, "d81vwef")
        with self.recorder.use_cassette("TestComment.test_refresh"):
            assert len(comment.replies) == 0
            comment.refresh()
            assert len(comment.replies) > 0
github praw-dev / praw / tests / integration / models / reddit / test_comment.py View on Github external
def test_distinguish__sticky(self, _):
        self.reddit.read_only = False
        with self.recorder.use_cassette(
            "TestCommentModeration.test_distinguish__sticky"
        ):
            Comment(self.reddit, "da2g5y6").mod.distinguish(sticky=True)
github thecsw / memeinvestor_bot / src / comment_worker.py View on Github external
def edit_wrap(self, body):
    logging.info(" -- editing response")

    if config.POST_TO_REDDIT:
        try:
            return self.edit(body)
        # TODO: get rid of this broad except
        except Exception as e:
            logging.error(e)
            traceback.print_exc()
            return False
    else:
        logging.info(body)
        return False

praw.models.Comment.reply_wrap = reply_wrap
praw.models.Comment.edit_wrap = edit_wrap

class CommentWorker():
    """
    This class is responsible for everything that happens
    in the comment. With some regex rules, it sees all of
    the commands and it has methods to execute on demand
    """
    multipliers = {
        'k': 1e3,
        'm': 1e6,
        'b': 1e9,
        't': 1e12,
        'quad': 1e15,
        # Has to be above q, or regex will stop at q instead of searching for quin/quad
        'quin': 1e18,
github danthedaniel / psraw / psraw / endpoints.py View on Github external
LIMIT_DEFAULT = 50
BASE_ADDRESS = 'https://apiv2.pushshift.io/reddit'
ENDPOINTS = {
    'comment_search': {
        'params': {
            'after': int,
            'before': int,
            'limit': int,
            'q': str,
            'sort': sort_type,
            'subreddit': str,
            'author': str
        },
        'limit': 500,
        'return_type': praw.models.Comment,
        'url': '/search/comment/'
    },
    'submission_search': {
        'params': {
            'after': int,
            'limit': int,
            'q': str,
            'sort': sort_type,
            'subreddit': str
        },
        'limit': 250,
        'return_type': praw.models.Submission,
        'url': '/search/submission/'
    }
github PurelyApplied / roll_one_for_me / rofm / classes / core / worknodes / requests.py View on Github external
return super(PrivateMessage, self).__str__()

    def __repr__(self):
        return super(PrivateMessage, self).__repr__()

    def _my_work_resolver(self):
        self.additional_work = [
            parsers.RedditDomainUrls(self.args),
            parsers.Message(self.args),
            parsers.SpecialRequest(self.args)
        ]


@dataclass
class UsernameMention(core.Worknode):
    args: praw.models.Comment
    kwargs: Dict[str, Any] = field(default_factory=dict)

    workload_type: core.WorkloadType = core.WorkloadType.request_type_username_mention
    name: str = "Request via username mention"

    def __str__(self):
        return super(UsernameMention, self).__str__()

    def __repr__(self):
        return super(UsernameMention, self).__repr__()

    def _my_work_resolver(self):
        # Until it is decided otherwise, a mention gets three actions:
        # (1) Look at the comment itself for a table
        # (2) Look for reddit-domain links to parse.
        # (2.1) Distinguish from links to submission (which also get top-level comments) and
github vihanggodbole / Search-for-reddit-saved-posts / search_saved_posts.py View on Github external
return  # exit the script if unable to login

    print('Welcome /u/{}. I will help you search through your saved posts on reddit :)'.format(redditor))
    saved = redditor.saved(limit=None)

    saved_posts = []
    saved_comments = []
    saved_links = []

    for post in saved:  # separate out posts and comments
        if isinstance(post, praw.models.Submission):
            if 'reddit' in post.url:
                saved_posts.append(post)
            else:
                saved_links.append(post)
        elif isinstance(post, praw.models.Comment):
            saved_comments.append(post)

    saved_posts_title = {}
    saved_comments_body = {}
    saved_links_title = {}

    for post in saved_posts:    # create a list of saved posts' titles
        saved_posts_title[post.id] = post.title

    for comment in saved_comments:  # create a list of saved comment's body
        saved_comments_body[comment.id] = comment.body

    for post in saved_links:    # create a list of saved links' titles
        saved_links_title[post.id] = post.title

    while(True):
github just-an-dev / sodogetip / commands / register.py View on Github external
address=user.address,
            spendable_balance=str(spendable_balance),
            spendable_value_usd=str(spendable_value_usd),
            unconfirmed_balance=str(unconfirmed_balance),
            unconfirmed_value_usd=str(unconfirmed_value_usd),
            pending_tips=str(pending_tips),
            pending_tips_value_usd=str(pending_tips_value_usd)
        )
        tittle_reply = 'you are already registered'

    # send PM so just reply
    if type(msg) is Message:
        msg.reply(content_reply)

    # we have just comment so send info in PM
    if type(msg) is Comment:
        user.send_private_message(tittle_reply, content_reply)