Ejemplo n.º 1
0
arg = sys.argv[1]


def print_posts_with_comments(existing_posts_with_comments):
    """Prints the dist of posts which already have comments from the bot.

    :param existing_posts_with_comments: the dict mapping post IDs to ExistingComment objects.
    :type existing_posts_with_comments: dict of <string, ExistingComment>
    """
    for post_id, e_c_obj in sorted(existing_posts_with_comments.items()):
        print("in post " + post_id + ": " + str(e_c_obj))


def print_found_mentions(found_mentions):
    """Prints the list of found mentions.

    :param found_mentions: list of PostWithMentions objects
    """
    for pwm_obj in found_mentions:
        print(pwm_obj)


if 'm' in arg:  # mentions found
    print("Mentions found:")
    print_found_mentions(tools.load_found_mentions())

if 'p' in arg:  # posts with comments
    print("Posts with comments:")
    print_posts_with_comments(tools.load_posts_with_comments())
"""Deletes a comment ONLY FROM the pickle of posts with comments. DOES NOT delete comment from reddit.com."""

# You might need to move this to the project's root folder for it to work.

import sys
import tools

if len(sys.argv) != 2:
    print("usage: delete_post_with_comment.py post_id")
    exit(1)

post_id = sys.argv[1]
posts_with_comments = tools.load_posts_with_comments()

pwc_obj = posts_with_comments.get(post_id, None)
if pwc_obj is None:
    print("Key \"{}\" not found.".format(post_id))
    exit(1)

print(pwc_obj)
if input("Delete this? ") == "y":
    del posts_with_comments[post_id]
    tools.save_posts_with_comments(posts_with_comments)
    print("Deleted.")
else:
    print("Not deleted.")