-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_email.py
50 lines (37 loc) · 1.12 KB
/
get_email.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
import config
import requests
import json
import csv
filename = "Canvas_Email_AdminID.csv"
csv_file = open(filename, 'w')
csv_file.write('canvas_id,login_id,email\n')
headers = {'Authorization' : 'Bearer ' + '%s' % config.API_KEY}
def build_line(canvas_id):
#print(courseID)
try:
url = config.API_URL + 'api/v1/users/' + canvas_id
results = requests.get(url, headers = headers)
response = results.text
user = json.loads(response)
email = user['email']
hawk_id = user['login_id']
line = canvas_id
line += ',' + hawk_id
line += ',' + email + '\n'
return line
except:
print("Email Not Found: " + str(canvas_id))
return None
def build_file():
with open('adminID.csv', 'r', newline='') as user_list:
reader = csv.reader(user_list, delimiter=',')
for row in reader:
canvas_id = row[0]
line = build_line(canvas_id)
if line != None:
csv_file.write(line)
print("done processing lines...")
def main():
build_file()
if __name__ == "__main__":
main()