]> git.cameronkatri.com Git - cgit.git/blob - filters/email-gravatar.py
git: update to v2.26.0
[cgit.git] / filters / email-gravatar.py
1 #!/usr/bin/env python3
2
3 # Please prefer the email-gravatar.lua using lua: as a prefix over this script. This
4 # script is very slow, in comparison.
5 #
6 # This script may be used with the email-filter or repo.email-filter settings in cgitrc.
7 #
8 # The following environment variables can be used to retrieve the configuration
9 # of the repository for which this script is called:
10 # CGIT_REPO_URL ( = repo.url setting )
11 # CGIT_REPO_NAME ( = repo.name setting )
12 # CGIT_REPO_PATH ( = repo.path setting )
13 # CGIT_REPO_OWNER ( = repo.owner setting )
14 # CGIT_REPO_DEFBRANCH ( = repo.defbranch setting )
15 # CGIT_REPO_SECTION ( = section setting )
16 # CGIT_REPO_CLONE_URL ( = repo.clone-url setting )
17 #
18 # It receives an email address on argv[1] and text on stdin. It prints
19 # to stdout that text prepended by a gravatar at 10pt.
20
21 import sys
22 import hashlib
23 import codecs
24
25 email = sys.argv[1].lower().strip()
26 if email[0] == '<':
27 email = email[1:]
28 if email[-1] == '>':
29 email = email[0:-1]
30
31 page = sys.argv[2]
32
33 sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach())
34 sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
35
36 md5 = hashlib.md5(email.encode()).hexdigest()
37 text = sys.stdin.read().strip()
38
39 print("<img src='//www.gravatar.com/avatar/" + md5 + "?s=13&amp;d=retro' width='13' height='13' alt='Gravatar' /> " + text)