File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1
1
# pylint: disable=bare-except
2
2
3
+ import hashlib
4
+ import urllib
5
+
3
6
from conditional import app
4
7
from conditional .models .models import FreshmanAccount
5
8
from conditional .util .cache import service_cache
@@ -31,11 +34,31 @@ def check_current_student(username):
31
34
return ldap_is_current_student (member )
32
35
33
36
37
+ @service_cache (maxsize = 256 )
38
+ def get_rit_image (username : str ) -> str :
39
+ if username :
40
+ addresses = [username + "@rit.edu" , username + "@g.rit.edu" ]
41
+ for addr in addresses :
42
+ url = (
43
+ "https://gravatar.com/avatar/"
44
+ + hashlib .md5 (addr .encode ("utf8" )).hexdigest ()
45
+ + ".jpg?d=404&s=250"
46
+ )
47
+ try :
48
+ with urllib .request .urlopen (url ) as gravatar :
49
+ if gravatar .getcode () == 200 :
50
+ return url
51
+ except :
52
+ continue
53
+ return "https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
54
+
55
+
34
56
@app .context_processor
35
57
def utility_processor ():
36
58
return {
37
59
"get_csh_name" : get_csh_name ,
38
60
"get_freshman_name" : get_freshman_name ,
61
+ "get_rit_image" : get_rit_image ,
39
62
"get_member_name" : get_member_name ,
40
63
"check_current_student" : check_current_student ,
41
64
}
You can’t perform that action at this time.
0 commit comments