-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpicssheet.py
58 lines (43 loc) · 1.56 KB
/
picssheet.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
# convert a list of student ids into an html page with their pictures
# useful for recognising students in a class
import covscraper
import getpass
import sys
import base64
import re
def process( session, username ):
if username.isdigit():
sid = username
else:
sid = covscraper.aulaapi.email_to_id(session, username)
details = covscraper.studentapi.get_student_details( session, sid )
return details
if __name__ == "__main__":
try:
username = sys.argv[1]
except IndexError:
username = input("Username: ")
try:
password = sys.argv[2]
except IndexError:
password = getpass.getpass("Password: ")
session = covscraper.auth.Authenticator(username,password)
sys.stdout.write( "<html>\n<body>\n" )
if sys.stdin.isatty():
try:
sid = sys.argv[3]
except IndexError:
sid = input("Student username/email: ")
print( process(session, sid) )
else:
for line in sys.stdin:
line = line.strip()
try:
details = process( session, line )
response = session.get( details["image"] )
image = f"data:{response.headers['Content-Type']};base64,{str(base64.b64encode(response.content).decode('utf-8'))}"
sys.stdout.write( f"<b>{details['firstName']} {details['lastName']}</b></br>\n")
sys.stdout.write( f'<img src="{image}" /><br><br>\n' )
except covscraper.studentapi.NoStudent:
pass
sys.stdout.write( "</body>\n</html>\n" )