Beispiel #1
0
def replace(old_un, new_un):
    users = helpers.load_data("user_list")
    users[users.index(old_un)] = new_un
    helpers.write_data("user_list", users)

    reddit = helpers.initialize_reddit()
    if not config.testing:
        try:
            reddit.subreddit(config.target_subreddit).flair.set(
                redditor=old_un, text="Moved to /u/{}".format(new_un)
            )
            reddit.subreddit(config.target_subreddit).contributor.remove(old_un)
        except (praw.exceptions.PRAWException, prawcore.PrawcoreException):
            # Deleted user, most likely
            pass
        main.flair_users(
            [new_un], reddit, config.flair_normal, number_adjustment=users.index(new_un)
        )
        main.add_users([new_un], reddit)
        participated = set(helpers.load_data("participated"))
        if old_un in participated:
            participated.add(new_un)
            helpers.write_data("participated", list(participated))
    else:
        print(
            "Flaired and removed /u/{}; Flaired and added /u/{}".format(old_un, new_un)
        )

    if config.update_sidebar:
        updates.update_sidebar(users)
Beispiel #2
0
def main(new_users):
    reddit = helpers.initialize_reddit()

    user_list = helpers.load_data("user_list")

    new_users = [user for user in new_users if user not in user_list]

    if not new_users:
        helpers.write_log_trash(
            "All re-adds already on the memberlist {}".format(helpers.date_string()),
            "",
        )
        sys.exit(1)

    daddy.add_users(new_users, reddit)
    daddy.flair_users(
        new_users, reddit, config.flair_normal, number_adjustment=len(user_list)
    )

    insert_users_to_userlist(new_users)
    user_list = helpers.load_data("user_list")

    title, body = build_post(new_users, len(user_list) - len(new_users) + 1)
    daddy.make_post(title, body, reddit, distinguish=True, sticky=False)

    if config.update_sidebar:
        updates.update_sidebar(user_list)
Beispiel #3
0
def new_sub():
    reddit = helpers.initialize_reddit()
    main.check_permissions(reddit)
    user_list = helpers.load_data("user_list")
    main.flair_users(user_list, reddit, config.flair_normal)
    if config.change_title:
        updates.change_title()
    if config.update_sidebar:
        updates.update_sidebar(user_list)
    main.add_users(user_list, reddit)
    helpers.write_data("participated", [])
Beispiel #4
0
def main():
    user_list = helpers.load_data("user_list")
    reddit = helpers.initialize_reddit()
    stats = helpers.load_data("stats")

    if user_list and ("--ignore-active-community"
                      not in sys.argv):  # checks if the user-list is non-empty
        msg = "Userlist is non-empty. Exiting. Call with --ignore-active-community to run anyway"
        helpers.write_log_trash("Failed {}".format(helpers.date_string()), msg)
        raise ActiveCommunity(msg)

    new_users, new_user_urls = helpers.load_data("potential_adds")
    helpers.write_log_trash("New users {}".format(helpers.date_string()),
                            new_users)

    post_text_items = [daddy.build_new_text(new_users, 1), "\n"]

    if config.entry_comments:
        post_text_items.append("[Comments for entry]({})".format(
            daddy.build_and_post_gist(new_users, new_user_urls)))
    if config.stats_section:
        post_text_items.append("# Info:\n\n")
        post_text_items.append("- {} users added".format(len(new_users)))
        diff = len(new_users)
        change = "+{}".format(diff) if diff >= 0 else str(diff)
        post_text_items.append("- Membercap: {} ({})".format(
            len(new_users), change))

    post_text = "\n".join(post_text_items)

    title = config.main_log_title
    if config.title_date:
        title = helpers.date_string() + " - " + title
    if config.title_number:
        stats["log_count"] += 1
        title += " #{}".format(stats["log_count"])

    daddy.make_post(title, post_text, reddit)

    if config.change_title:
        updates.change_title()

    daddy.add_users(new_users, reddit)
    daddy.flair_users(new_users, reddit, config.flair_new)

    if config.update_sidebar:
        updates.update_sidebar(new_users)

    stats["last_full_run"] = time.time()
    helpers.write_data("stats", stats)
    helpers.write_data("user_list", new_users)
    helpers.write_data("participated", [])
Beispiel #5
0
def re_flair(count):
    users = helpers.load_data("user_list")
    reddit = helpers.initialize_reddit()
    main.flair_users(users[:count], reddit, config.flair_normal)