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 @@

Active Packets

{{ get_rit_name(packet.freshman_username) }} {{ get_rit_name(packet.freshman_username) }} diff --git a/packet/templates/packet.html b/packet/templates/packet.html index 5d1a1e5d..62708a74 100644 --- a/packet/templates/packet.html +++ b/packet/templates/packet.html @@ -110,7 +110,7 @@
Upperclassmen Score - {{ '%0.2f' % upper_score }}%
{{ sig.freshman_username }} {{ get_rit_name(sig.freshman_username) }} diff --git a/packet/templates/upperclassman.html b/packet/templates/upperclassman.html index 4dc40e1c..07268c5b 100644 --- a/packet/templates/upperclassman.html +++ b/packet/templates/upperclassman.html @@ -33,7 +33,7 @@

{{ get_rit_name(packet.freshman_username) }} {{ get_rit_name(packet.freshman_username) }}