Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update delete_users.py #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions delete_users.py
Original file line number Diff line number Diff line change
@@ -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 = ""

Expand All @@ -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"

Expand Down Expand Up @@ -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"

Expand All @@ -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)

Expand All @@ -127,8 +121,6 @@ def DeleteUsers():

deactivedUsers = GetPaginatedResponse(url)

userInfoList = []

deactivedUsersCount = 0
deletedUsersCount = 0
notDeletedUserCount = 0
Expand All @@ -148,7 +140,7 @@ def DeleteUsers():

if response == "<Response [204]>":

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"]])
Expand All @@ -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))



Expand All @@ -173,4 +165,4 @@ def DeleteUsers():

if __name__ == "__main__":

DeleteUsers()
DeleteUsers()