def main():
    # pp = PrettyPrinter(indent=4)
    slack = Slacker(SLACK_AUTH_TOKEN)
    # TODO: might be more helpful if members_to_keep was specified as emails or Slack usernames instead of Slack IDs

    group_details = get_slack_groups(slack)
    # pp.pprint(group_details)

    # for testing a small number, not all in file:
    # groups_to_clear = ["cp1406-2017-team01", "cp1406-2017-team02"]
    # for group in groups_to_clear:
    groups_file = open(FILENAME, "r")
    for group in groups_file:
        group = group.strip()
        try:
            print("For {}: {}".format(group, group_details[group]))
            group_id, members = group_details[group]
            kick_members(slack, group_id, members, members_to_keep)
            print("Kicking from {}".format(group))
            # set "purpose" of group to blank
            slack.groups.set_purpose(group_id, "")
            # ARCHIVE GROUP!!
            slack.groups.archive(group_id)
        except:
            pass
    groups_file.close()
def main():
    slack = Slacker(SLACK_AUTH_TOKEN)
    pp = PrettyPrinter(indent=4)

    # get all students and subjects they do
    groups_students = get_group_lists(STUDENT_FILE)
    pp.pprint(groups_students)
    return
    # get all users from Slack
    slack_user_details = get_slack_users(slack, pp)

    # get groups like {'name': (group ID, [member IDs])}
    group_details = get_slack_groups(slack)
    # pp.pprint(group_details)
    # return

    missing = []
    invited_count = 0

    for group, students in groups_students.items():
        print("Group: {}".format(group))
        for email in students:
            # get slack ID or if user is missing, keep track of them separately
            try:
                slack_id = slack_user_details[email][0]
                # print(group, slack_id, email)
            except KeyError:
                missing.append(email)
                continue

            # invite students to their groups
            try:
                if slack_id not in group_details[group][1]:
                    print("Inviting {} to {}".format(email, group))
                    invited_count += 1
                    try:
                        slack.groups.invite(group_details[group][0], slack_id)
                    except:
                        print("ERROR with Slack call, probably missing group for {}\n".format(group))
            except:
                print("ERROR with lookup, probably missing group for {}\n".format(group))

    print("Invited people {} times".format(invited_count))
    print("\n{} people not in Slack:\n{}".format(len(missing), "\n".join(missing)))
    # output text file with missing students in form ready for bulk Slack invite (comma separated)
    with open("output/nonslackers.txt", "w") as f:
        f.write(", ".join(missing))
def main():
    pp = PrettyPrinter(indent=4)
    slack = Slacker(SLACK_AUTH_TOKEN)
    # TODO: might be more helpful if members_to_keep was specified as emails or Slack usernames instead of Slack IDs

    group_details = get_slack_groups(slack)
    # pp.pprint(group_details)

    # for testing a small number, not all in file:
    # groups_to_clear = ["cp1406-2016-team04", "cp1406-2016-team06"]
    # for group in groups_to_clear:
    groups_file = open(FILENAME, "r")
    for group in groups_file:
        group = group.strip()
        print("For {}: {}".format(group, group_details[group]))
        group_id, members = group_details[group]
        kick_members(slack, group_id, members, members_to_keep)
        print("Kicking from {}".format(group))
        # set "purpose" of group to blank
        slack.groups.set_purpose(group_id, "")
    groups_file.close()
Beispiel #4
0
def main():
    slack = Slacker(SLACK_AUTH_TOKEN)
    # pp = PrettyPrinter(indent=4)

    # get all students and their groups
    groups_students = get_group_lists(STUDENT_FILE)
    # pp.pprint(groups_students)

    # get all users from Slack
    slack_user_details = get_slack_users(slack)

    # get all groups like {'name': (group ID, [member IDs])}
    group_details = get_slack_groups(slack)
    # pp.pprint(group_details)

    missing = []
    invited_count = 0

    for group_name, students in groups_students.items():
        print("Group: {}".format(group_name))
        # make group if it doesn't exist
        try:
            group_id = group_details[group_name][0]
        except KeyError:
            print("No {} group. Adding it now.".format(group_name))
            response = slack.groups.create(group_name)
            try:
                # add new group details to current groups dictionary in same format (id, [members])
                group_id = response.body['group']['id']
                group_details[group_name] = (group_id, [])
            except:
                print("Creating group {} failed. Exiting.".format(group_name))
                return False

        # add students to group
        for email in students:
            # get slack ID or if user is missing, keep track of them separately
            try:
                slack_id = slack_user_details[email][0]
                # print(group, slack_id, email)
            except KeyError:
                missing.append(email)
                continue

            # invite students to their groups
            try:
                if slack_id not in group_details[group_name][1]:
                    print("Inviting {} to {}".format(email, group_name))
                    invited_count += 1
                    try:
                        slack.groups.invite(group_id, slack_id)
                    except:
                        print(
                            "ERROR with Slack call. Maybe missing group {} or user {}\n"
                            .format(group_name, email))
            except:
                print("ERROR with lookup, probably missing group for {}\n".
                      format(group_name))

    print("Invited people {} times".format(invited_count))
    print("\n{} people not in Slack:\n{}".format(len(missing),
                                                 "\n".join(missing)))
    # output text file with missing students in form ready for bulk Slack invite (comma separated)
    with open("output/nonslacker_groups.txt", "w") as f:
        f.write(", ".join(missing))