filters/email-gravatar.py (view raw)
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
21import sys
22import hashlib
23import codecs
24
25email = sys.argv[1].lower().strip()
26if email[0] == '<':
27 email = email[1:]
28if email[-1] == '>':
29 email = email[0:-1]
30
31page = sys.argv[2]
32
33sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach())
34sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
35
36md5 = hashlib.md5(email.encode()).hexdigest()
37text = sys.stdin.read().strip()
38
39print("<img src='//www.gravatar.com/avatar/" + md5 + "?s=13&d=retro' width='13' height='13' alt='Gravatar' /> " + text)