def clear_sub(credentials, sub, num=20):
    """Removes all* old posts from a sub (use with care)

    * up to 900
    :param credentials:
    :param sub:
    :return:
    """
    num = min(num, 900)
    if num < 0:
        num = int(1e6)
    mypraw = create_multiprocess_praw(credentials)
    sub = get_subreddit(credentials, mypraw, sub)
    old_stream = p.helpers.submission_stream(mypraw, sub, limit=num)
    results = []
    try:
        #delete all old posts
        for i in range(num):
            try:
                post = old_stream.next()
                Actions.remove_post(post, delete=True)
                print("# {} deleted...".format(i))
            except AttributeError:
                # Post or Comment may have been deleted between retrieving it
                # and accessing its fields
                pass
    except AssertionError, e:
        logging.log(logging.DEBUG, str(e) + "\nNo Posts!")
Ejemplo n.º 2
0
def main():
    from CredentialsImport import CRImport
    import utilitymethods as u
    import logging

    testbed = None
    saved_posts = {}

    # mark true if the script should remove all old posts from the testbed
    DELETE_OLD = True

    #import credentials
    credentials = CRImport("TestCredentials.cred")

    #create my reddit
    r = u.create_multiprocess_praw(credentials)

    #get testbed sub
    testbed = u.get_subreddit(credentials, r)

    #create datasource object
    datasource = u.get_subreddit(credentials, r, credentials["DATAMININGSUB"])

    if DELETE_OLD:
        old_stream = praw.helpers.submission_stream(r, testbed, limit=POST_LIMIT)
        results = []
        try:
            #delete all old posts
            for post in old_stream:
                try:
                    Actions.remove_post(post, delete=True)
                    print("deleted old post: %s..." % post.title[:20])
                except AttributeError:
                    # Post or Comment may have been deleted between retrieving it
                    # and accessing its fields
                    pass
        except AssertionError, e:
            logging.log(logging.DEBUG, str(e) + "\nNo Posts!")
Ejemplo n.º 3
0
def testRemovePost(sub, post):
    # spawn a Removal action
    print "Remove Post:"
    val = a.remove_post(post)
    print "Passed" if val else "Failed"
    return val
Ejemplo n.º 4
0
 def remove_and_post(self, post, comment):
     Actions.remove_post(self, post)
     Actions.make_comment(post, comment, dist=True)