Using a csv list of usernames to delete AGOL users

05-20-2019 12:37 PM
New Contributor II

Hello - I've been working on writing some scripts to help clean up our AGOL membership.

This community has been great - I've been using Richard Stokes question (and notebook) to help get started:

I'm running into some problems deleting a list of around 140 users based on a CSV file (our GIS group came up with a list of criteria and created and exported this list of usernames from AdminTools). It's a single column CSV with just usernames (the column heading is "Username").

As I understand it, I need get each user account, release their licenses, delete their content, and then delete the member. 

I seem to be doing something very basic incorrectly in my initial loop through the list of usernames to get each user account from AGOL.

#Import modules
from arcgis.gis import GIS
import csv

#Declare GIS
gis = GIS("", "adminName", "psswrd")

#Make list of users to delete
userDelete = []

with open(r"4_22_2019InactiveUsers2.csv") as f_input:
csv_input = csv.DictReader(f_input)
   for row in csv_input:
   users = row["username:Username")]

---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)<ipython-input-28-d415de218329> in <module>      2     csv_input = csv.DictReader(f_input)      3     for row in csv_input:----> 4         users = row["username:Username")]      5         userDelete.append(users)      6  TypeError: unhashable type: 'list'

Any suggestions appreciated - I'm new   Thank you!

Tags (2)
0 Kudos
2 Replies
Esri Contributor

The following works for me to create the list of users that need to be deleted from a csv of their usernames in the first column.

with open(csvPath) as f_input:
   csv_input = csv.reader(f_input, delimiter=",")
   for row in csv_input:
      users ="username:{}".format(row[0]))
      if (len(users)>0): # only append if there are search results
New Contributor II

Thanks - this worked very well!