示例#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())
    :param running_on_own: whether file is being ran by itself or imported by reddit_bot.py
    :type running_on_own: bool
    :param reddit: authorized reddit praw object
    :type reddit: praw.Reddit
    :param new_mentions_list: list of mentions
    :type new_mentions_list: list
    """
    if new_mentions_list:
        new_mention = new_mentions_list.pop(0)
    else:
        print("No more mentions.")
        return
    _post_comment_helper(new_mention, reddit)
    if running_on_own:
        tools.save_found_mentions(new_mentions_list)
    post_comments(new_mentions_list, reddit, running_on_own)


existing_posts_with_comments = tools.load_posts_with_comments()
db = db_core.load_database()

if __name__ == "__main__":
    print('{id}{_}{author}{_}{title}{_}{action}{_}current mentions{_}previous mentions'
          .format(id = trunc_pad("id"),
                  author = trunc_pad("author"),
                  title = trunc_pad("title"),
                  action = trunc_pad("action"),
                  _ = '  '))
    post_comments(tools.load_found_mentions(), tools.auth_reddit(), running_on_own = True)