Import users from a CSV file with columns:
        username
        first_name
        last_name
        email
        sites: a comma-separated list of sites
        groups: a comma-separated list of groups
        job_title

def import_users(
    path,
    resource_name=None,
    send_email_to_user=None,
    alternate_email=None,
    verbose=None,
    export_to_file=None,
    **kwargs,
):
    """Import users from a CSV file with columns:
        username
        first_name
        last_name
        email
        sites: a comma-separated list of sites
        groups: a comma-separated list of groups
        job_title
    """
    users = []
    with open(path) as f:
        reader = csv.DictReader(f)
        for user_data in reader:
            username = user_data.get("username")
            site_names = user_data.get("sites").lower().split(",")
            group_names = user_data.get("groups").lower().split(",")
            first_name = user_data.get("first_name")
            last_name = user_data.get("last_name")
            email = user_data.get("email")
            o = UserImporter(
                username=username,
                first_name=first_name,
                last_name=last_name,
                email=email,
                site_names=site_names,
                group_names=group_names,
                resource_name=resource_name,
                send_email_to_user=send_email_to_user,
                alternate_email=alternate_email,
                verbose=verbose,
                **kwargs,
            )
            users.append(
                {
                    "username": o.user.username,
                    "password": o.password,
                    "first_name": o.user.first_name,
                    "last_name": o.user.last_name,
                    "sites": o.site_names,
                    "groups": o.group_names,
                }
            )
    if export_to_file:
        fieldnames = [
            "username",
            "password",
            "first_name",
            "last_name",
            "sites",
            "groups",
        ]
        with open(path + "new.csv", "w+") as f:
            writer = csv.DictWriter(f, fieldnames=fieldnames)
            writer.writeheader()
            for user in users:
                writer.writerow(user)