# Requires admin role.
import csv, time
from agoTools.admin import Admin

agoAdmin = Admin('<username>') # Replace <username> with your admin username.
outputFile = 'c:/temp/users.csv'

users = agoAdmin.getUsers()
roles = agoAdmin.getRoles()

#Make a dictionary of the roles so we can convert custom roles from their ID to their associated name.
roleLookup = {}
for role in roles:
    roleLookup[role["id"]] = role["name"]

with open(outputFile, 'wb') as output:
    dataWriter = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    # Write header row.
    dataWriter.writerow(['Full Name',
                         'Email',
                         'Username',
                         'Role',
                         'Date Created'])
    # Write user data.
    for user in users:
        #get role name from the id. If it's not in the roles, it's one of the standard roles so just use it.
        roleID = user['role']
        roleName = roleLookup.get(roleID,roleID)
        dataWriter.writerow([user['fullName'].encode('utf-8'),
                             user['email'].encode('utf-8'),
                             user['username'].encode('utf-8'),
Exemple #2
0
from agoTools.admin import Admin

# Obtain AGOL instance credentials from a non-repo file in this directory.
try:
    from credentials import *
except:
    print "./credentials.py missing"
    sys.exit(0)

# Generate AGOL instance URL from AGOL subdomain.
portalURL = 'https://' + agolSubdomain + '.maps.arcgis.com'

agolAdmin = Admin(username,portalURL,password) # Replace <username> with your admin username.
users = agolAdmin.getUsers()
roles = agolAdmin.getRoles()

# Make a dictionary of the roles so we can convert custom roles from their ID to their associated name.
roleLookup = {}
for role in roles:
    roleLookup[role[u'id']] = role[u'name']
    
# Designate output file for CSV user list.
# TODO: Check that directory exists, and that file name isn't already in use.
#outputFile = u'c:/temp/' + agolSubdomain + u' ' + time.strftime("%Y-%m-%d-%H%M%S",time.gmtime()) + u'.csv'
outputFile = u'E:\knoop\Google Drive\My LSA IT\Esri\ArcGIS Online\AGOL exportUserListCSV/' + agolSubdomain + u' ' + time.strftime("%Y-%m-%d-%H%M%S",time.gmtime()) + u'.csv'
with open(outputFile, 'wb') as output:
    
    dataWriter = csv.writer(output, dialect='excel' )
    
    # Write header row.
Exemple #3
0
userFirstName = str(userFirstName)
userLastName = str(userLastName)
userRole = str(userRole)
provider = str(provider)

arcpy.AddMessage("Logging in...")
try:
    agoAdmin = Admin(adminAccount, password=adminPassword)
except:
    arcpy.AddError(
        "Login failed. Please re-enter your admin username and password.")
    sys.exit()

##Get roles from the portal so we can translate the user-entered name to the role id that the api needs.
##Also confirm that the user-entered role is valid.
allRoles = agoAdmin.getRoles()
##getRoles doesn't return predefined system roles, so we'll add those
roles = {
    'Administrator': 'org_admin',
    'Publisher': 'org_publisher',
    'Author': 'org_author',
    'User': '******'
}
for role in allRoles:
    roles[role["name"]] = role["id"]
if not userRole in roles.keys():
    arcpy.AddError(userRole + " is not a valid role.")
    sys.exit()

roleId = roles[userRole]
from agoTools.admin import Admin

# Obtain AGOL instance credentials from a non-repo file in this directory.
try:
    from credentials import *
except:
    print "./credentials.py missing"
    sys.exit(0)

# Generate AGOL instance URL from AGOL subdomain.
portalURL = 'https://' + agolSubdomain + '.maps.arcgis.com'

agolAdmin = Admin(username,portalURL,password) # Replace <username> with your admin username.
users = agolAdmin.getUsers()
roles = agolAdmin.getRoles()

# Make a dictionary of the roles so we can convert custom roles from their ID to their associated name.
roleLookup = {}
for role in roles:
    roleLookup[role[u'id']] = role[u'name']
    
# Designate output file for CSV user list.
# TODO: Check that directory exists, and that file name isn't already in use.
#outputFile = u'c:/temp/' + agolSubdomain + u' ' + time.strftime("%Y-%m-%d-%H%M%S",time.gmtime()) + u'.csv'
outputFile = u'E:\knoop\Google Drive\My LSAIT-ARS\Esri\ArcGIS Online\AGOL exportUserListCSV/' + agolSubdomain + u' ' + time.strftime("%Y-%m-%d-%H%M%S",time.gmtime()) + u'.csv'
with open(outputFile, 'wb') as output:
    
    dataWriter = csv.writer(output, dialect='excel' )
    
    # Write header row.