def main(mods, defaults, cousins):

    if defaults:
        mods = set(mods)
        mods.union(settings.DEFAULT_MODS)
        mods = list(mods)

    if not mods:
        print('No moderators specified. Quitting.')
        return

    r = Reddit('Mass Moderator Invite v0.1 /u/{}'.format(settings.USERNAME))
    r.oauth()

    subs = [sub['name'] for sub in settings.CHILD_SUBS]
    if cousins:
        cuzs = set(sub['name'] for sub in settings.COUSIN_SUBS)
        cuzs.update(subs)
        subs = sorted(cuzs)

    for sub in subs:
        s = r.get_subreddit(sub)
        cur_mods = [u.name for u in s.get_moderators()]
        need_mods = [m for m in mods if m not in cur_mods]

        if not need_mods:
            print('No mods needed for /r/{}.'.format(sub))

        for mod in need_mods:
            print('Inviting {} to moderate /r/{}.'.format(mod, sub))
            s.add_moderator(mod)
Example #2
0
def main(mods, defaults, cousins):

    if defaults:
        mods = set(mods)
        mods.union(settings.DEFAULT_MODS)
        mods = list(mods)

    if not mods:
        print('No moderators specified. Quitting.')
        return

    r = Reddit('Mass Moderator Invite v0.1 /u/{}'.format(settings.USERNAME))
    r.oauth()

    subs = [sub['name'] for sub in settings.CHILD_SUBS]
    if cousins:
        cuzs = set(sub['name'] for sub in settings.COUSIN_SUBS)
        cuzs.update(subs)
        subs = sorted(cuzs)

    for sub in subs:
        s = r.get_subreddit(sub)
        cur_mods = [u.name for u in s.get_moderators()]
        need_mods = [m for m in mods if m not in cur_mods]

        if not need_mods:
            print('No mods needed for /r/{}.'.format(sub))

        for mod in need_mods:
            print('Inviting {} to moderate /r/{}.'.format(mod, sub))
            s.add_moderator(mod)
Example #3
0
def main():
    r = Reddit('{} hot_sister v3 - /u/{}'.format(settings.NETWORK_NAME,
                                                 settings.USERNAME))
    r.oauth()

    # places multireddit
    places_multi = r.get_multireddit(settings.USERNAME, PLACES_MULTI_NAME)
    places_list_text = ''
    for post in places_multi.get_hot(limit=POSTS_TO_LIST):
        places_list_text += ' * [{}](https://redd.it/{})\n'.format(post.title,
                                                                   post.id)

    # decades multireddit
    decades_multi = r.get_multireddit(settings.USERNAME, DECADES_MULTI_NAME)
    decades_list_text = ''
    for post in decades_multi.get_hot(limit=POSTS_TO_LIST):
        decades_list_text += ' * [{}](https://redd.it/{})\n'.format(post.title,
                                                                    post.id)

    # bring it together
    combined_text = "* Places:\n{}\n\n* Times:\n{}".format(places_list_text,
                                                           decades_list_text)

    # set up all the children
    children = sorted([sub['name'] for sub in settings.CHILD_SUBS])
    for child in children:
        print("running on {}".format(child))
        sub = r.get_subreddit(child)

        current_sidebar = sub.get_settings()['description']
        current_sidebar = html.unescape(current_sidebar)

        # ew
        replace_pattern = re.compile('{}.*?{}'.format(
            re.escape(START_DELIM),
            re.escape(END_DELIM)
        ), re.IGNORECASE | re.DOTALL | re.UNICODE)

        # ew
        new_sidebar = re.sub(
            replace_pattern,
            '{}\\n\\n{}\\n{}'.format(
                START_DELIM,
                combined_text,
                END_DELIM
            ),
            current_sidebar
        )

        try:
            sub.update_settings(description=new_sidebar)
        except HTTPException as e:
            LOG.error(
                "{0} on {1} while updating the sidebar".format(
                    f_e_o(type(e), e)[0], child)
                )
            continue
Example #4
0
def main(print_mods):
    """Find subs without mods and disenfranchised mods"""

    mods = settings.DEFAULT_MODS

    r = Reddit('Moderator Auditor v0.1')
    r.oauth()

    subs = sorted([sub['name'] for sub in settings.CHILD_SUBS])
    empty_subs = list()

    orphan_mods = dict()
    s = r.get_subreddit(settings.PARENT_SUB)
    main_sub_mods = [u.name for u in s.get_moderators()]

    for sub in subs:
        s = r.get_subreddit(sub)
        cur_mods = [u.name for u in s.get_moderators()]
        real_mods = [m for m in cur_mods if m not in mods]

        if not real_mods:
            empty_subs.append(sub)

        else:
            if print_mods:
                print('{} : {}'.format(sub, real_mods))

            for m in [i for i in real_mods if i not in main_sub_mods]:
                orphan_mods[m] = orphan_mods.get(m, []) + [sub]

    print()
    print('Unmoderated Subreddits: {}'.format(len(empty_subs)))
    print('-----------------------')

    for sub in sorted(empty_subs):
        print(sub)

    print()
    print('Orphaned Moderators: {}'.format(len(orphan_mods)))
    print('-------------------------')

    for m, s in orphan_mods.items():
        print('{} : {}'.format(m, s))
Example #5
0
def main(print_mods):
    """Find subs without mods and disenfranchised mods"""
    
    mods = settings.DEFAULT_MODS

    r = Reddit('Moderator Auditor v0.1')
    r.oauth()

    subs = sorted([sub['name'] for sub in settings.SLAVE_SUBS])
    empty_subs = list()
    
    orphan_mods = dict()
    s = r.get_subreddit(settings.MASTER_SUB)
    main_sub_mods = [u.name for u in s.get_moderators()]
    
    for sub in subs:
        s = r.get_subreddit(sub)
        cur_mods = [u.name for u in s.get_moderators()]
        real_mods = [m for m in cur_mods if m not in mods]

        if not real_mods:
            empty_subs.append(sub)

        else:
            if print_mods:
                print('{} : {}'.format(sub, real_mods))
            
            for m in [i for i in real_mods if i not in main_sub_mods]:
                orphan_mods[m] = orphan_mods.get(m, []) + [sub]

    print()
    print('Unmoderated Subreddits: {}'.format(len(empty_subs)))
    print('-----------------------')

    for sub in sorted(empty_subs):
        print(sub)

    print()
    print('Orphaned Moderators: {}'.format(len(orphan_mods)))
    print('-------------------------')

    for m, s in orphan_mods.items():
        print('{} : {}'.format(m, s))
Example #6
0
def main():
    r = Reddit('{} hot_sister v3 - /u/{}'.format(settings.NETWORK_NAME,
                                                 settings.USERNAME))
    r.oauth()

    # places multireddit
    places_multi = r.get_multireddit(settings.USERNAME, PLACES_MULTI_NAME)
    places_list_text = ''
    for post in places_multi.get_hot(limit=POSTS_TO_LIST):
        places_list_text += ' * [{}](https://redd.it/{})\n'.format(
            post.title, post.id)

    # decades multireddit
    decades_multi = r.get_multireddit(settings.USERNAME, DECADES_MULTI_NAME)
    decades_list_text = ''
    for post in decades_multi.get_hot(limit=POSTS_TO_LIST):
        decades_list_text += ' * [{}](https://redd.it/{})\n'.format(
            post.title, post.id)

    # bring it together
    combined_text = "* Places:\n{}\n\n* Times:\n{}".format(
        places_list_text, decades_list_text)

    # set up all the children
    children = sorted([sub['name'] for sub in settings.CHILD_SUBS])
    for child in children:
        print("running on {}".format(child))
        sub = r.get_subreddit(child)

        current_sidebar = sub.get_settings()['description']
        current_sidebar = html.unescape(current_sidebar)

        # ew
        replace_pattern = re.compile(
            '{}.*?{}'.format(re.escape(START_DELIM), re.escape(END_DELIM)),
            re.IGNORECASE | re.DOTALL | re.UNICODE)

        # ew
        new_sidebar = re.sub(
            replace_pattern,
            '{}\\n\\n{}\\n{}'.format(START_DELIM, combined_text,
                                     END_DELIM), current_sidebar)

        try:
            sub.update_settings(description=new_sidebar)
        except HTTPException as e:
            LOG.error("{0} on {1} while updating the sidebar".format(
                f_e_o(type(e), e)[0], child))
            continue
Example #7
0
def main():
    r = Reddit('{} hot_sister v3 - /u/{}'.format(settings.NETWORK_NAME, settings.USERNAME))
    r.oauth()

    # places multireddit
    places_multi = r.get_multireddit(settings.USERNAME, PLACES_MULTI_NAME)
    places_list_text = str()
    for post in places_multi.get_hot(limit=POSTS_TO_LIST):
        places_list_text += ' * [%s](%s)\n' % (post.title, post.permalink)

    # decades multireddit
    decades_multi = r.get_multireddit(settings.USERNAME, DECADES_MULTI_NAME)
    decades_list_text = str()
    for (i, post) in enumerate(DECADES_MULTI.get_hot(limit=POSTS_TO_LIST)):
        decades_list_text += ' * [%s](%s)\n' % (post.title, post.permalink)

    # bring it together
    combined_text= "* Places:\n{}\n\n* Times:\n{}".format(places_list_text, decades_list_text)

    # set up all the children
    children = sorted([sub['name'] for sub in settings.CHILD_SUBS])
    for child in children:
        print("running on {}".format(child))
        sub = r.get_subreddit(child)

        current_sidebar = sub.get_settings()['description']
        current_sidebar = html.unescape(current_sidebar)

        # ew
        replace_pattern = re.compile('%s.*?%s'.format(
                re.escape(START_DELIM),
                re.escape(END_DELIM)),
            re.IGNORECASE|re.DOTALL|re.UNICODE)

        # ew
        new_sidebar = re.sub(replace_pattern,
                            '{}\\n\\n{}\\n{}'.format(
                                START_DELIM,
                                combinex_text,
                                END_DELIM),
                            current_sidebar)

        sub.update_settings(description=new_sidebar)
Example #8
0
def main():
    r = Reddit('{} hot_sister v3 - /u/{}'.format(settings.NETWORK_NAME,
                                                 settings.USERNAME))
    r.oauth()

    # places multireddit
    places_multi = r.get_multireddit(settings.USERNAME, PLACES_MULTI_NAME)
    places_list_text = str()
    for post in places_multi.get_hot(limit=POSTS_TO_LIST):
        places_list_text += ' * [%s](%s)\n' % (post.title, post.permalink)

    # decades multireddit
    decades_multi = r.get_multireddit(settings.USERNAME, DECADES_MULTI_NAME)
    decades_list_text = str()
    for (i, post) in enumerate(DECADES_MULTI.get_hot(limit=POSTS_TO_LIST)):
        decades_list_text += ' * [%s](%s)\n' % (post.title, post.permalink)

    # bring it together
    combined_text = "* Places:\n{}\n\n* Times:\n{}".format(
        places_list_text, decades_list_text)

    # set up all the children
    children = sorted([sub['name'] for sub in settings.CHILD_SUBS])
    for child in children:
        print("running on {}".format(child))
        sub = r.get_subreddit(child)

        current_sidebar = sub.get_settings()['description']
        current_sidebar = html.unescape(current_sidebar)

        # ew
        replace_pattern = re.compile(
            '%s.*?%s'.format(re.escape(START_DELIM), re.escape(END_DELIM)),
            re.IGNORECASE | re.DOTALL | re.UNICODE)

        # ew
        new_sidebar = re.sub(
            replace_pattern,
            '{}\\n\\n{}\\n{}'.format(START_DELIM, combinex_text,
                                     END_DELIM), current_sidebar)

        sub.update_settings(description=new_sidebar)
Example #9
0
def main(history_days):
    """Process modlogs to identify inactive mods"""

    mods = settings.DEFAULT_MODS

    r = Reddit(
        '{} ModLog Auditor v0.1 - /u/{}'.format(
            settings.NETWORK_NAME, settings.USERNAME)
    )
    r.oauth()

    subs = sorted([sub['name'] for sub in settings.CHILD_SUBS])

    end_utc = gmtime(time.time() - 60 * 60 * 24 * history_days)
    end_date = date(end_utc[0], end_utc[1], end_utc[2])

    for sub in subs:
        print('Processing {} modlog...'.format(sub))
        done = False
        last = None
        count = 0

        s = r.get_subreddit(sub)
        all_mods = [u.name for u in s.get_moderators()]
        real_mods = [m for m in all_mods if m not in mods]

        # If no real moderators, don't process this subreddit modlog
        if not real_mods:
            continue
        else:
            mod_action_count = dict()
            mod_last_action = dict()

            while not done:
                log = list(s.get_mod_log(limit=50, params={"after": last}))

                if len(log) == 0:
                    done = True
                    break
                else:
                    last = log[-1].id

                for log_entry in [l for l in log if l.mod in real_mods]:
                    created_utc = log_entry.created_utc
                    time_utc = gmtime(created_utc)
                    date_utc = date(time_utc[0], time_utc[1], time_utc[2])

                    if date_utc >= end_date:
                        mod_action_count[log_entry.mod] = mod_action_count.get(
                            log_entry.mod, 0) + 1

                        if date_utc > mod_last_action.get(log_entry.mod,
                                                          date(1901, 1, 1)):
                            mod_last_action[log_entry.mod] = date_utc
                    else:
                        # Reached end date
                        done = True
                        break

                if count >= 5000:
                    done = True
                    break

                count += 100

        print('Subredit Moderation Log Stats '
              'for {}:\t\t({} entries parsed)'.format(sub, count))
        for m in real_mods:
            print('    {}:\n\tActions: {}'
                  '  \tLast Active: {}\n'.format(
                      m, mod_action_count.get(m, 0),
                      mod_last_action.get(m, date(1901, 1, 1))))