diff --git a/packet/context_processors.py b/packet/context_processors.py index 52347203..06733448 100644 --- a/packet/context_processors.py +++ b/packet/context_processors.py @@ -1,7 +1,8 @@ """ Context processors used by the jinja templates """ - +import hashlib +import urllib from functools import lru_cache from datetime import datetime @@ -18,6 +19,7 @@ def get_csh_name(username): except: return username + def get_roles(sig): """ Converts a signature's role fields to a dict for ease of access. @@ -49,6 +51,18 @@ def get_rit_name(username): return username +@lru_cache(maxsize=128) +def get_rit_image(username): + if username: + addresses = [username + "@rit.edu", username + "@g.rit.edu"] + for addr in addresses: + url = "https://gravatar.com/avatar/" + hashlib.md5(addr.encode("utf8")).hexdigest() + ".jpg?d=404&s=250" + gravatar = urllib.request.urlopen(url) + if gravatar.getcode() == 200: + return url + return "https://www.gravatar.com/avatar/freshmen?d=mp&f=y" + + def log_time(label): """ Used during debugging to log timestamps while rendering templates diff --git a/packet/templates/active_packets.html b/packet/templates/active_packets.html index fd5fdf20..ad3c9889 100644 --- a/packet/templates/active_packets.html +++ b/packet/templates/active_packets.html @@ -42,7 +42,7 @@