-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdelete_inactive_user.py
141 lines (115 loc) · 3.56 KB
/
delete_inactive_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import csv
import shutil
import time
import os
import re
import glob
from resources.pathes import CHROME_PROFILES
USERS_IN_TXT = []
def count_users_left():
with open('./resources/dataOG.txt', mode='r') as dt:
reader = csv.reader(dt)
for row in reader:
USERS_IN_TXT.append(row)
dt.close()
def delete_users():
list_to_remove = []
# load users to delete and append to list to delete
with open('./resources/DATADELETE.txt', mode='r+') as dt:
reader = csv.reader(dt)
for row in reader:
a = ''.join(row)
list_to_remove.append(a)
dt.close()
# print(list_to_remove)
new_list = []
# compare og data with to_delete > create new list, with working users
with open('./resources/dataOG.txt', mode='r+') as fp:
reader = csv.reader(fp)
for row in reader:
b = ''.join(row)
if b not in list_to_remove:
new_list.append(b)
fp.close()
# write new list in the main user file
with open('./resources/dataOG.txt', mode='w') as dg:
for item in new_list:
# print(item)
dg.write(item + '\n')
dg.close()
def delete_user_chrome():
list_to_remove_chrome = []
# load users to delete and append to list to delete
with open('./resources/DATADELETE.txt', mode='r') as dt:
reader = csv.reader(dt)
for row in reader:
a = ''.join(row)
username = re.split(':', a)[0]
list_to_remove_chrome.append(username)
dt.close()
# print(list_to_remove_chrome) # list of users to be deleted
for user in list_to_remove_chrome:
path = f'{CHROME_PROFILES}{user}'
if os.path.exists(path):
try:
shutil.rmtree(path)
except:
pass
try:
os.rmdir(path)
except:
pass
print(f'[+] User deleted: {user}')
else:
print('\033[91m'+f'[-] User NOT deleted!: {user}'+'\033[0m')
def all_usr_chrome():
all_user = []
# load users to delete and append to list to delete
with open('./resources/dataOG.txt', mode='r') as dt:
reader = csv.reader(dt)
for row in reader:
a = ''.join(row)
username = re.split(':', a)[0]
all_user.append(username)
dt.close()
# print(all_user)
# print(len(all_user))
# print('all users in txt')
all_usr_dir = glob.glob(CHROME_PROFILES + '*')
reformat_usr_dir = []
for user in all_usr_dir:
a = (''.join(user))
a = re.split('/', a)[6]
reformat_usr_dir.append(a)
# time.sleep(1)
# print(reformat_usr_dir)
# print(len(reformat_usr_dir))
# print('all users in directory')
test_list = []
for u in reformat_usr_dir:
if u not in all_user:
path = f'{CHROME_PROFILES}{u}'
if os.path.exists(path):
# print(u + 'NOT EXISTEND')
test_list.append(u)
try:
shutil.rmtree(path)
except:
pass
try:
os.rmdir(path)
except:
pass
print(f'[+] User deleted: {u}')
def clear_txt():
# clear DATADELETE.txt
with open('./resources/DATADELETE.txt', mode='w') as dtf:
dtf.write('')
dtf.close()
if __name__ == '__main__':
count_users_left()
print(len(USERS_IN_TXT))
# all_usr_chrome()
# delete_users()
# delete_user_chrome()
# clear_txt()