Select to view content in your preferred language

Query Against AGOL User Store

319
1
04-21-2023 04:32 AM
kapalczynski
Regular Contributor

I have a script that reads my AGOL User store and finds users that are about to be deactivated.  Although when I run it I get this:

ERROR:

Matplotlib created a temporary config/cache directory at C:\Users\J~1.KAP\AppData\Local\Temp\matplotlib-i0q8mino because the default path (H:\.matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.

I am not sure what is trying to use Matplotlib in my script nor how to fix this... Any ideas?

 

from arcgis.gis import GIS
import arcgis 
import csv
import time
from datetime import date, datetime, timedelta

agol_username = 'xxxx' 
agol_password = 'xxxx'  
output_csv = r'C:\Users\xxx\Desktop\GIS_projects\AGOL_Python\UsersAboutToExpire.csv'
search_user = '*'
gis = GIS('https://xxxx.maps.arcgis.com', agol_username, agol_password)
user_list = gis.users.search(query=search_user, max_users=2000)
roles = gis.users.roles.all()
rol_ids = {role.role_id: role.name for role in roles}
output = []

def main():
    with open(output_csv, 'w', encoding='utf-8') as file:
         csvfile = csv.writer(file, delimiter=',', lineterminator='\n')
         csvfile.writerow(["username",  
                           "email",
                           "roleID",
                           "level",
                           "disabled",
                           "role",
                           "licenseType",
                           "lastLogin",
                           "daysSince"
                         ])
         counter = 0   
         for user in user_list:

            lastLogintime = user.lastLogin/1000
            lastLoginTimeConvert = (datetime.utcfromtimestamp(lastLogintime).strftime('%Y-%m-%d %H:%M:%S'))
            format = '%Y-%m-%d %H:%M:%S'
            lastLoginDate = datetime.strptime(lastLoginTimeConvert, format)
            lastLoginDATE = datetime.now() - lastLoginDate
            lastLoginDAYS = lastLoginDATE.days
            varDisabvled = user.disabled

            #if lastLoginDAYS > 80:
            if lastLoginDAYS in range(80,90):
                if varDisabvled == False:             
                    try:
                        varusername = user.username  
                        varemail = user.email
                        varRoleID = rol_ids[user.roleId]
                        varlevel = user.level
                        vardisabledValue = user.disabled
                        varrole = user.role
                        varlicenceType = user.userLicenseTypeId
                        varLastLogin = lastLoginDate
                        varLastLoginDays = lastLoginDAYS

                        z = (varusername if isinstance(varusername, list) else [varusername]) + [varemail] + [varRoleID] + [varlevel] + [vardisabledValue] +  [varrole] + [varlicenceType] + [varLastLogin] + [varLastLoginDays]
                        output.append(z)
                        counter += 1
                        csvfile.writerow([varusername,  
                                    varemail,
                                    varRoleID,
                                    varlevel,
                                    vardisabledValue,
                                    varrole,
                                    varlicenceType,
                                    varLastLogin,
                                    varLastLoginDays      
                                    ])
                    except KeyError as e:
                        print(user.username, e)

if __name__ == '__main__':
    main()

 

0 Kudos
1 Reply
kapalczynski
Regular Contributor

Anyone see this error before or know how to get rid of it?

0 Kudos