-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_pcc_tools.py
52 lines (40 loc) · 1.32 KB
/
test_pcc_tools.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
import csv
import os
root_dir = os.path.dirname(__file__)
def user_lst_from_roster_csv(csv_file):
username_lst = []
with open(csv_file, newline='') as f:
reader = csv.reader(f, delimiter=',', quotechar='|')
for row in reader:
for entry in row:
if '@' in entry:
username = entry.split('@')[0]
username_lst.append(username)
return username_lst
def user_lst_from_email_roster(txt_file):
'''
takes a roster.txt with
and returns a list with
['peter.marchineo', 'even.baker','nelly.manning','jess.rod2']
'''
with open(txt_file, 'r') as f:
return [x.split('@')[0] for x in f.readlines()]
whitelist = set()
extra_users = ['peter.marchineo','faculty.name1','faculty.name2','test.student2']
for f in os.listdir(root_dir):
if f.endswith('roster.csv'):
user_list = user_lst_from_roster_csv(os.path.join(root_dir, f))
if f.endswith('roster.txt'):
user_list = user_lst_from_email_roster(os.path.join(root_dir, f))
if user_list:
for user in user_list:
whitelist.add(user)
if extra_users:
for extra_user in extra_users:
whitelist.add(extra_user)
for x in whitelist:
print(x)