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 11# pylint: disable=bare-except
22
3+ import hashlib
4+ import urllib
5+
36from conditional import app
47from conditional .models .models import FreshmanAccount
58from conditional .util .cache import service_cache
@@ -31,11 +34,31 @@ def check_current_student(username):
3134 return ldap_is_current_student (member )
3235
3336
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+
3456@app .context_processor
3557def utility_processor ():
3658 return {
3759 "get_csh_name" : get_csh_name ,
3860 "get_freshman_name" : get_freshman_name ,
61+ "get_rit_image" : get_rit_image ,
3962 "get_member_name" : get_member_name ,
4063 "check_current_student" : check_current_student ,
4164 }
You can’t perform that action at this time.
0 commit comments