]> gitweb.ps.run Git - ps-cgit/blob - filters/email-gravatar.py
email-gravatar.lua: fix for lua 5.2
[ps-cgit] / 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
24 email = sys.argv[1].lower().strip()
25 if email[0] == '<':
26         email = email[1:]
27 if email[-1] == '>':
28         email = email[0:-1]
29
30 page = sys.argv[2]
31
32 md5 = hashlib.md5(email.encode()).hexdigest()
33 text = sys.stdin.read().strip()
34
35 print("<img src='//www.gravatar.com/avatar/" + md5 + "?s=13&d=retro' style='height:10pt;width:10pt'> " + text)