Skip to content

Commit 902c653

Browse files
authored
Merge pull request #166 from devinmatte/freshman_image
Using freshmen gravatar images
2 parents 6f056d8 + 971c24b commit 902c653

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

packet/context_processors.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
Context processors used by the jinja templates
33
"""
4-
4+
import hashlib
5+
import urllib
56
from functools import lru_cache
67
from datetime import datetime
78

@@ -18,6 +19,7 @@ def get_csh_name(username):
1819
except:
1920
return username
2021

22+
2123
def get_roles(sig):
2224
"""
2325
Converts a signature's role fields to a dict for ease of access.
@@ -49,6 +51,18 @@ def get_rit_name(username):
4951
return username
5052

5153

54+
@lru_cache(maxsize=128)
55+
def get_rit_image(username):
56+
if username:
57+
addresses = [username + "@rit.edu", username + "@g.rit.edu"]
58+
for addr in addresses:
59+
url = "https://gravatar.com/avatar/" + hashlib.md5(addr.encode("utf8")).hexdigest() + ".jpg?d=404&s=250"
60+
gravatar = urllib.request.urlopen(url)
61+
if gravatar.getcode() == 200:
62+
return url
63+
return "https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
64+
65+
5266
def log_time(label):
5367
"""
5468
Used during debugging to log timestamps while rendering templates

packet/templates/active_packets.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h4 class="page-title">Active Packets</h4>
4242
<a href="{{ url_for('freshman_packet', packet_id=packet.id) }}">
4343
<img class="eval-user-img"
4444
alt="{{ get_rit_name(packet.freshman_username) }}"
45-
src="https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
45+
src="{{ get_rit_image(packet.freshman_username) }}"
4646
width="25"
4747
height="25"/> {{ get_rit_name(packet.freshman_username) }}
4848
</a>

packet/templates/packet.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
110110
<tr {% if sig.signed %}style="background-color: #4caf505e" {% endif %}>
111111
<td>
112112
<img class="eval-user-img" alt="{{ sig.freshman_username }}"
113-
src="https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
113+
src="{{ get_rit_image(sig.freshman_username) }}"
114114
width="25" height="25"/>
115115
{{ get_rit_name(sig.freshman_username) }}
116116
</td>

packet/templates/upperclassman.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h3 class="page-title">
3333
<a href="{{ url_for('freshman_packet', packet_id=packet.id) }}">
3434
<img class="eval-user-img"
3535
alt="{{ get_rit_name(packet.freshman_username) }}"
36-
src="https://www.gravatar.com/avatar/freshmen?d=mp&f=y"
36+
src="{{ get_rit_image(packet.freshman_username) }}"
3737
width="25"
3838
height="25"/>
3939
{{ get_rit_name(packet.freshman_username) }}

0 commit comments

Comments
 (0)