From ad6c12dec17a9420ed0dde3ba3f5b059bfccfcf2 Mon Sep 17 00:00:00 2001 From: Gabriel Sroka Date: Thu, 27 Jan 2022 09:00:45 -0800 Subject: [PATCH] Update delete_users.py upgrade to run on Python 3. i tested a little bit, but not a lot --- delete_users.py | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/delete_users.py b/delete_users.py index bc58029..8aba3a9 100644 --- a/delete_users.py +++ b/delete_users.py @@ -1,14 +1,8 @@ import requests import json -import re -import sys import csv -import openpyxl -reload(sys) -sys.setdefaultencoding('utf-8') - orgName = "org-domain.oktapreview" apiKey = "" @@ -33,9 +27,9 @@ def GetPaginatedResponse(url): if "errorCode" in responseJSON: - print "\nYou encountered following Error: \n" - print responseJSON - print "\n" + print("\nYou encountered following Error: \n") + print(responseJSON) + print("\n") return "Error" @@ -84,9 +78,9 @@ def DELETERequest(url): responseJSON = response if "errorCode" in responseJSON: - print "\nYou encountered following Error: \n" - print responseJSON - print "\n" + print("\nYou encountered following Error: \n") + print(responseJSON) + print("\n") return "Error" @@ -101,21 +95,21 @@ def DeleteUsers(): ##### CSV Files ##### # Deactive Users - deactiveUsers = open("Deactive-Users.csv", "wb") + deactiveUsers = open("Deactive-Users.csv", "w") deactiveWriter = csv.writer(deactiveUsers) deactiveWriter.writerow(["firstName", "lastName", "email", "login", "status"]) #Deleted Users - deletedUsers = open("Deleted-Users.csv", "wb") + deletedUsers = open("Deleted-Users.csv", "w") deletedWriter = csv.writer(deletedUsers) deletedWriter.writerow(["firstName", "lastName", "email", "login", "status"]) #Not Deleted Users - notDeletedUsers = open("Not-Deleted-Users.csv", "wb") + notDeletedUsers = open("Not-Deleted-Users.csv", "w") notDeletedWriter = csv.writer(notDeletedUsers) @@ -127,8 +121,6 @@ def DeleteUsers(): deactivedUsers = GetPaginatedResponse(url) - userInfoList = [] - deactivedUsersCount = 0 deletedUsersCount = 0 notDeletedUserCount = 0 @@ -148,7 +140,7 @@ def DeleteUsers(): if response == "": - print str(user["profile"]["login"]) + " is Deleted" + print(str(user["profile"]["login"]) + " is Deleted" ) deletedUsersCount += 1 deletedWriter.writerow([user["profile"]["firstName"], user["profile"]["lastName"], user["profile"]["email"], user["profile"]["login"], user["status"]]) @@ -161,9 +153,9 @@ def DeleteUsers(): - print "Deactivated Users: " + str(deactivedUsersCount) - print "Deleted Users: " + str(deletedUsersCount) - print "Not Deleted Users: " + str(notDeletedUserCount) + print("Deactivated Users: " + str(deactivedUsersCount)) + print("Deleted Users: " + str(deletedUsersCount)) + print("Not Deleted Users: " + str(notDeletedUserCount)) @@ -173,4 +165,4 @@ def DeleteUsers(): if __name__ == "__main__": - DeleteUsers() \ No newline at end of file + DeleteUsers()