How to use the praw.objects 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 / old / test_multireddit.py View on Github external
def test_multireddit_representations(self):
        multi = objects.Multireddit(self.r, author='Foo', name='Bar')
        self.assertEqual("Multireddit(author='Foo', name='Bar')", repr(multi))
        self.assertEqual('Bar', str(multi))
github SIlver-- / remindmebot-reddit / remindmebot_search.py View on Github external
def main():
    print "start"
    checkcycle = 0
    while True:
        try:
            # grab the request
            request = requests.get('https://api.pushshift.io/reddit/search?q=%22RemindMe%22&limit=100', 
                headers = {'User-Agent': 'RemindMeBot-Agent'})
            json = request.json()
            comments =  json["data"]
            read_pm()
            for rawcomment in comments:
                # object constructor requires empty attribute
                rawcomment['_replies'] = ''
                comment = praw.objects.Comment(reddit, rawcomment)
                check_comment(comment)

            # Only check periodically 
            if checkcycle >= 5:
                check_own_comments()
                checkcycle = 0
            else:
                checkcycle += 1

            print "----"
            time.sleep(30)
        except Exception as err:
            print traceback.format_exc()           
            time.sleep(30)
        """
        Will add later if problem with api.pushshift
github bgw / NotVeryCleverBot / src / database.py View on Github external
def __json_to_comment(reddit_session, json):
        json = dict(json)
        if "metadata" in json: del json["metadata"]
        return praw.objects.Comment(reddit_session, json)
github PurelyApplied / roll_one_for_me / master_branch_roll_one.py View on Github external
def __str__(self):
        via = None
        if type(self.origin) == praw.objects.Comment:
            via = "mention in {}".format(self.origin.submission.title)
        elif type(self.origin) == praw.objects.Message:
            via = "private message"
        else:
            via = "a mystery!"
        return "/u/{} via {}".format(self.origin.author, via)
github jaijuneja / reddit-nlp / redditnlp / __init__.py View on Github external
def get_vocabulary(comments):

            vocab = Counter()
            num_comments = 0
            for comment in comments:
                if isinstance(comment, praw.objects.Comment):
                    try:
                        # Get the word counts for the comment
                        vocab += self.get_word_count(comment.body, stemming=stemming)
                        num_comments += 1

                    except ValueError:
                        pass
                elif isinstance(comment, praw.objects.MoreComments) and get_all_comments:
                    new_vocab, num_new_comments = get_vocabulary(comment.comments)
                    vocab += new_vocab
                    num_comments += num_new_comments

            return vocab, num_comments
github PurelyApplied / roll_one_for_me / roll_one.py View on Github external
def get_post_text(post):
    '''Returns text to parse from either Comment or Submission'''
    if type(post) == praw.objects.Comment:
        return post.body
    elif type(post) == praw.objects.Submission:
        return post.selftext
    else:
        lprint("Attempt to get post text from"
               " non-Comment / non-Submission post; returning empty string")
        return ""
github justcool393 / TotesMessenger / MetaBot.py View on Github external
if sid in linkedsrc:
        return False;


    if lid in linked or check_commmented(linkedp):
        success = edit_post(get_bot_comment(linkedp), submission);
        if success:
            linkedsrc.append(sid);
        return success;

    if check_commmented(linkedp):
        linked.append(lid);
        linkedsrc.append(lid);
        return False;

    if isinstance(linkedp, praw.objects.Comment):
        linked.append(lid);
        linkedsrc.append(sid);
        comment(linkedp, submission, srlower == "circlejerk");
    elif isinstance(linkedp, praw.objects.Submission):
        post(linkedp, submission, srlower == "circlejerk");
    else:
        logging.error("Not a Comment or Submission! (ID: " + id + ")");
        return False;

    linked.append(lid);
    linkedsrc.append(sid);
    return True;
github PurelyApplied / roll_one_for_me / master_branch_roll_one.py View on Github external
def __str__(self):
        via = None
        if type(self.origin) == praw.objects.Comment:
            via = "mention in {}".format(self.origin.submission.title)
        elif type(self.origin) == praw.objects.Message:
            via = "private message"
        else:
            via = "a mystery!"
        return "/u/{} via {}".format(self.origin.author, via)
github LunarMist / redditbot / base / redditbot / base / utils.py View on Github external
def has_replied(praw_object, username):
    """
    Returns True if the specified user has a comment in the top level replies of the given submission/comment/message,
    and False otherwise.
    For comments, submissions, messages ONLY.
    """
    if type(praw_object) == praw.objects.Message:
        # TODO: Fix this to actually check properly
        # If it's not the first message in the PM thread, we replied previously.
        # This is not the best method, and it is a bit flakey,
        # but good enough for most cases
        if praw_object.first_message is not None:
            return True
        return False
    elif type(praw_object) == praw.objects.Submission:
        praw_object.replace_more_comments(limit=None)
        replies = praw_object.comments
    elif type(praw_object) == praw.objects.Comment:
        replies = praw_object.replies
    else:
        raise Exception("Object must be an instance of praw.objects.Comment/Submission/Message")

    if not replies:
github PurelyApplied / roll_one_for_me / roll_one.py View on Github external
def get_post_text(post):
    '''Returns text to parse from either Comment or Submission'''
    if type(post) == praw.objects.Comment:
        return post.body
    elif type(post) == praw.objects.Submission:
        return post.selftext
    else:
        lprint("Attempt to get post text from"
               " non-Comment / non-Submission post; returning empty string")
        return ""