diff options
Diffstat (limited to 'filters/email-libravatar-hover.py')
-rwxr-xr-x | filters/email-libravatar-hover.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/filters/email-libravatar-hover.py b/filters/email-libravatar-hover.py new file mode 100755 index 0000000..352122b --- /dev/null +++ b/filters/email-libravatar-hover.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import sys +import hashlib +import codecs +import os + +# Read and process the email address from command line arguments +email = sys.argv[1].lower().strip() +if email[0] == '<': + email = email[1:] +if email[-1] == '>': + email = email[:-1] + +# Read the page argument (not used in this script but passed for compatibility) +page = sys.argv[2] + +# Ensure correct encoding for stdin and stdout +sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach()) +sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) + +# Calculate MD5 hash of the email +md5 = hashlib.md5(email.encode()).hexdigest() + +# Read the standard input to get the buffer text +buffer = sys.stdin.read().strip() + +# Determine the base URL based on HTTPS environment variable +baseurl = "https://seccdn.libravatar.org/" if os.getenv("HTTPS") else "http://cdn.libravatar.org/" + +# Generate the HTML output with Libravatar images +html_output = ( + f"<span class='libravatar'>" + f"<img class='inline' src='{baseurl}avatar/{md5}?s=13&d=retro' width='13' height='13' alt='Libravatar' />" + f"<img class='onhover' src='{baseurl}avatar/{md5}?s=128&d=retro' width='128' height='128' alt='Libravatar' />" + f"</span> {buffer}" +) + +# Print the HTML output +print(html_output) |